How to calculate start date of the week based on week number ?

i need to get week number of the current date and based on that i need to calculate start date falling in the same week for last year.
Eg. today is 31st week of year and 31st july date. so what will be the date on the 31st week of last year. i need the start date of that week.
we can calculate the week number by select to_char(sysdate,'ww') from dual.
DO we have a single line query for that or will it require writing a pl/sql block ?

you can try following query
it can be as inline but for more clean look and create it as select with include select
with t as
(select sysdate as dt from dual)
select to_char(prev_year_dt - to_char(prev_year_dt, 'D') + 1, 'DD.MM.YYYY') as start_of_week from (select
-- get day from prev year with the same week number
    case
           when to_number(to_char(add_months(dt, -12), 'WW')) > to_number(to_char(dt, 'WW')) then
            dt - (to_number(to_char(add_months(dt, -12), 'WW')) - to_number(to_char(dt, 'WW'))) * 7
           when to_number(to_char(add_months(dt, -12), 'WW')) < to_number(to_char(dt, 'WW')) then
            dt + (to_number(to_char(dt, 'WW')) - to_number(to_char(add_months(dt, -12), 'WW'))) * 7
           else
            add_months(dt, -12)
       end as prev_year_dt
  from t) t1good luck
Sergii
'Monday' is not first day of week in 100% ;)
Edited by: Galbarad on Jul 30, 2012 11:00 PM

Similar Messages

  • How to calculate start date and last date for current week

    Dear All.
    i want to calculate the start of the current week as well as the last date of the current week, our week start from Saturday and ends of Friday i.e. Saturday is the first day of the week and Friday is the last day of the week.
    How can i acheive this in universe Designer?.
    Please help...

    Hi
    the formulas in webi will be as follows
    for startdate
    =RelativeDate(LastDayOfWeek(CurrentDate());-8)
    for enddate:
    =RelativeDate(LastDayOfWeek(CurrentDate());-2)
    Regards,
    Ranganath

  • How to get start date of the period for a given date from cube

    I have a situation where i need to find the start day of the period for a given date. is there a way to know that. i want to use that in my report. i enter the date from my report(i have date parameter), depends on the date, i want to display the start day
    of the period. how can i write expression for that in my report?
    ram

    Hi ramprasad74,
    According to your description, you are using Analysis Services as a data source for the report, the cube has hierarchy: Fyear, FQuarter, FPeriod, fweek, Fdate. You want to add a date parameter to the report, after you changed value of the parameter, the
    report will return the first day of FPeriod.
    To achieve your goal, we need to add a parameter to the report, then use the parameter in mdx query. For detail information, please refer to the following steps:
    In the Report Data pane, right-click on a dataset created from a SQL Server Analysis Services data source type, and then click Query. The MDX query designer opens in Design mode.
    On the toolbar, click Design to toggle to Query mode.
    On the MDX query designer toolbar, click Query Parameters symbol. The Query Parameters dialog box opens.
    In the Parameter column, click <Enter Parameter>, and then type the name of a parameter.
    In the Dimension column, choose a value from the drop-down list.
    In the Hierarchy column, choose a value from the drop-down list.
    In the Default column, from the drop-down list, select a single value.
    Click OK. 
    In query designer dialog box, type the mdx query like below:
    with member [Measures].[FirstChild]
    as
    [Date].[Fiscal].currentmember.parent.firstchild.name
    select {[Measures].[FirstChild]} on 0,
    [Date].[Fiscal].[Date].members on 1
    from
    ( SELECT ( STRTOSET(@ParameterName, CONSTRAINED) ) on 0
    from
    [Cube]
    Here are relevant threads you can reference:
    https://social.msdn.microsoft.com/forums/sqlserver/en-US/c7146ac3-40ea-4d53-b321-c707aebbd405/how-to-pass-date-parameter-to-mdx-query
    https://social.msdn.microsoft.com/forums/sqlserver/en-US/fd12a865-bc90-4a65-af42-ce38a8cfa29b/pass-date-time-parameter-to-mdx-query-ssrs
    If you have any more questions, please feel free to ask.
    Thanks,
    Wendy Fu
    If you have any feedback on our support, please click
    here.

  • How to calculate a date in the future and set it as field value?

    I'm trying to set the value of a read-only field to a date and time 72 hours from the current date and time. Here's how I'm doing it now:
    var futureInMilliseconds = new Date().getTime() + 259200000; // current date and time + 72 hours in milliseconds
    field.value = new Date(futureInMilliseconds);
    The field is formatted as "m/d/yyyy h:MM tt". When I test this in the debugger I see it listing the correct date and time in the future, but the value applied to the field is always the current date and time. So, I'm having a difficult time getting this to work for something that should be fairly straight forward and simple. I'd appreciate any suggestions.

    What is the "field" object?
    What happen when you use "event" for the object and not "field"?
    Even if this script is placed at the document level or any other location, it is still a calculation. It just not a field Custom Calculation Script. You are adding one value to another to get a new value.

  • How do I change the start date for the week from Monday to Sunday on my iPhone 5?

    How do I change the start date for the week on iCal from Monday to Sunday on my iPhone5?

    Yes. On my new iPhone 5 the iCal week begins on a Monday not a Sunday and does not give me the option to edit in settings on the phone

  • How does the GR processing time affect the scheduling of the process order & the latest start date in the operation.

    Hi
    Can anyone explain  how does the GR processing time affect the scheduling of the process order & the latest start date in the operation overview.

    Hi
    GR processing time means number of workdays required after receiving the material in storage.
    Check this link:GR Processing time
    Regards,
    Anupam Sharma

  • How to get last date of the week

    hi,
    how to get last date of the week like FM WEEK_GET_FIRST_DAY gives the date of the first day of the week i need the date of the last day of the week..
    thnx

    data : p_week type KWEEK,
    p_Date type SYDATUM.
    p_week = <incoming value in week of year>
    CALL FUNCTION 'WEEK_GET_FIRST_DAY'
    EXPORTING
    week = p_week
    IMPORTING
    DATE = p_date
    EXCEPTIONS
    WEEK_INVALID = 1
    OTHERS = 2
    IF sy-subrc <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
    To get the last day of the week.
    p_date = p_date + 6.
    You can find the available fm in the system from se37 transaction code.

  • How to calculate first date and end date of this year in Query

    Hi Expert
    I want to calculate following dates with inputted date in query.
    I have no knowledge on ABAP and I just can create a query with simple logic.
    Could you teach me how to calculate following date?
    (If inputted date is April 12 2009)
    - First date of this year (Ex January 1 2009)
    - End date  of this year (Ex December 31 2009)
    - First date of last year (Ex January 1 2008)
    - End date of last year  (Ex December 31 2008)
    - First date of this month (Ex April 1 2009)
    Thank you!
    Take

    HR_JP_MONTH_BEGIN_END_DATE   use this FM to get the begin and end date of the Date you are passing. eg when u give input as 04/12/2009, it will return
    04/01/2009 as begin date
    04/30/2009 as end date
    pass the Year in this FM HR_E_GET_FISC_YEAR_DATES, you will get the Fiscal year Begin and End Dates
    Abh

  • Call object was called with start date in the previous month

    We have a single cycle maintenance plan for 30 days.
    Shift Factor Late Compl.   : 100%
    Tolerance                    :  10%
    Shift Factor Early Compl. :  100%
    Tolerance                    :    10%
    Cycle modification factor:    1
    Factory calendar            :  NIL
    Call horizon                    : 100%
    Scheduling period          :  90 DAY
    Scheduling indicator       : Time
    Call no . 11 was a plan date of 14.08.2009 has completion date 14.08.2009. Schedule type/status has "scheduled complete".
    Call no. 12 was called on 13.09.2009 which is in the past.
    Can someone explain why the system called the order with a starting date in the previuos month , that is , 13.09.2009.
    And how to rectify it to make it current date for the next call object?
    Thanks,
    Manohar

    I checked the algorithm for call no. 12
    Start of Cycle                07.08.2008
    Last planned date         14.08.2009
    Compl.Predecess           14.08.2009        Absolute shift                +   0 Da
    Planned cycle/offset      +    30 Da          Relative shift            0 % =   0 Da
    Shift                                 +     0 Da           erance value           0 % =   0 Da
    Planned Dates Due   13.09.2009    Completed on
    Last call on              15.10.2009    Called by               IP1020091015
    Workorder generated has start date 13.09.2009.
    Should we restart this plan , as the start dates in call object are at least 1 month old ?
    Thanks,
    Manohar

  • How to populate TableView data on the other screen TextField

    Hi guru’s
    I am having problem in populating data from a table in one screen to a Text Field in the other screen. I have two classes FirstClass containing a textbox and a button. On pressing a button a second window is opened containing a Table of values. As the user double clicks a row the value of the second column of the row should be inserted into the textbox of the FirstClass. Code of both the classes is attached. Thanking you in anticipation.
    import javafx.application.Application;
    import javafx.event.ActionEvent;
    import javafx.event.EventHandler;
    import javafx.geometry.Insets;
    import javafx.scene.Scene;
    import javafx.scene.control.Button;
    import javafx.scene.control.TextField;
    import javafx.scene.layout.GridPane;
    import javafx.scene.layout.StackPane;
    import javafx.stage.Stage;
    public class FirstClass extends Application {
    public static void main(String[] args) {
         launch(args);
    @Override
    public void start(final Stage primaryStage) {
         primaryStage.setTitle("First Class");
    GridPane gridpane = new GridPane();
              gridpane.setPadding(new Insets(5));
              gridpane.setHgap(5);
              gridpane.setVgap(5);
    final TextField userNameFld = new TextField();
    gridpane.add(userNameFld, 1, 1);
    Button btn = new Button();
    btn.setText("Show Table");
    gridpane.add(btn, 1, 3);
    btn.setOnAction(new EventHandler<ActionEvent>() {
    @Override
    public void handle(ActionEvent event) {
         String a = TableClass.showDialog(primaryStage, true, "Table Window" );
         userNameFld.setText(a);
    StackPane root = new StackPane();
    Scene scene =new Scene(root, 300, 250);
    root.getChildren().addAll(gridpane);
    primaryStage.setScene(scene);
    primaryStage.show();
    import javafx.beans.property.SimpleStringProperty;
    import javafx.collections.FXCollections;
    import javafx.collections.ObservableList;
    import javafx.event.EventHandler;
    import javafx.geometry.Insets;
    import javafx.scene.Scene;
    import javafx.scene.control.TableColumn;
    import javafx.scene.control.TableView;
    import javafx.scene.control.cell.PropertyValueFactory;
    import javafx.scene.input.MouseEvent;
    import javafx.scene.layout.GridPane;
    import javafx.scene.layout.StackPane;
    import javafx.stage.Modality;
    import javafx.stage.Stage;
    public class TableClass extends Stage {
         private static TableClass dialog;
         private static String value = "";
         public static class Person {
    private final SimpleStringProperty firstName;
    private final SimpleStringProperty lastName;
    private Person(String fName, String lName) {
    this.firstName = new SimpleStringProperty(fName);
    this.lastName = new SimpleStringProperty(lName);
    public String getFirstName() {
    return firstName.get();
    public void setFirstName(String fName) {
    firstName.set(fName);
    public String getLastName() {
    return lastName.get();
    public void setLastName(String fName) {
    lastName.set(fName);
         private TableView<Person> table = new TableView<Person>();
         private final ObservableList<Person> data =
         FXCollections.observableArrayList(
         new Person("JACK", "BROWN"),
         new Person("JOHN", "VIANNEYS"),
         new Person("MICHAEL", "NELSON"),
         new Person("WILLIAM", " CAREY")
         public TableClass(Stage owner, boolean modality, String title) {
              super();
              initOwner(owner);
              Modality m = modality ? Modality.APPLICATION_MODAL : Modality.NONE;
              initModality(m);
              setOpacity(1);
              setTitle(title);
              StackPane root = new StackPane();
              Scene scene = new Scene(root, 750, 750);
              setScene(scene);
              GridPane gridpane = new GridPane();
              gridpane.setPadding(new Insets(5));
              gridpane.setHgap(5);
              gridpane.setVgap(5);
              TableColumn firstNameCol = new TableColumn("First Name");
         firstNameCol.setMinWidth(100);
         firstNameCol.setCellValueFactory(
         new PropertyValueFactory<Person,String>("firstName")
         TableColumn lastNameCol = new TableColumn("Last Name");
         lastNameCol.setMinWidth(200);
         lastNameCol.setCellValueFactory(
         new PropertyValueFactory<Person,String>("lastName")
         table.setItems(data);
         table.getColumns().addAll(firstNameCol, lastNameCol);
         table.setOnMouseClicked(new EventHandler<MouseEvent>() {
                   public void handle(MouseEvent me) {
                        if (me.getClickCount() >= 2) {
                   String srr = table.getItems().get(table.getSelectionModel().getSelectedIndex()).getLastName();
                   value = srr;
                   dialog.hide();
         gridpane.add(table, 1, 5,1,20 );
              root.getChildren().add(gridpane);
         public static String showDialog(Stage stg, Boolean a , String title){
              dialog = new TableClass( stg,a, title);
              dialog.show();
              return value;
    }

    Cross posted
    http://www.coderanch.com/t/582014/JavaFX/java/populate-TableView-data-other-screen
    http://stackoverflow.com/questions/10734649/how-to-populate-tableview-data-on-the-other-screen-textfield-in-javafx-2-0
    Moderator advice: Please read the announcement(s) at the top of the forum listings and the FAQ linked from every page. They are there for a purpose.
    Then edit your post and format the code correctly.
    db

  • Duration between Start date of the project and user defined  Date

    Hi All,
    I need to calculate the the duration between the projects start  date and the date (month and year) the User defines. Also wat charateristics do we use to to restrict 0DATE_KYF to differentiate between forcast date and actual date.Any help will be appreciated

    You need to create formula variable for the date objects and used those variables to calculate the difference of the dates in either formula or calculated key figure.
    thanks.
    Wond

  • Position 1000001 not available for the start date of the infotype record

    Dear Experts/Gurus,
    I am getting the following error message "Position 1000001 not available for the start date of the infotype record" while trying to upload employees HR Master data in PA40.
    I know the reason why because the position is created on 01.05.2009 & employee DOJ is 01.02.2006 both are mismatch & the position date has to be changed earlier date than DOJ but i don't know how to do.
    Please let me know how to sort out this issue asap.
    Rgds,
    Vikrant

    Dear Friend,
    Use  PP02, select the position no, select infotype 1000 (Object), select planning status & validity(date) and then use the copy function to change the start date.
    Regards,
    Aks

  • How can I POST data within the same page if I have a A HREF -tag as input?

    How can I POST data within the same page if I have a <A HREF>-tag as input? I want the user to click on a line of text (from a database) and then some data should be posted.

    you can use like this or call javascript fuction and submit the form
    <form method=post action="/mypage">
    cnmsdesign.doc     
    </form>

  • How can I get Data from the Sound cart in Labview? Does a VI exist?

    How can I get Data from the Sound cart in Labview? Does a VI exist?

    Yes, there are VIs for acquiring data from Sound cards. And examples too. If you don't have LabVIEW yet, do a search on NI's site for example VIs.
    Khalid

  • Me and my partner are currently using the same apple id and have no space left on our devices. We are currently waiting on the iphone 6 plus to arrive and don't know how to transfer all data to the new phones.

    Me and my partner are currently using the same apple id and have no space left on our devices. We are currently waiting on the iphone 6 plus to arrive and don't know how to transfer all data to the new phones.?

    I don't know if I'm asking this all in a way that can be understood? Thanks ED3K, however that part I do understand (in the link you provided!)
    What I need to know is "how" I can separate or rather create another Apple ID for my son-who is currently using "my Apple ID?" If there is a way to let him keep "all" his info on his phone (eg-contacts, music, app's, etc.) without doing a "reset?') Somehow I need to go into his phone's setting-create a new Apple ID and possibly a new password so he can still use our combined iCloud & Itunes account?
    Also then letting me take back my Apple ID & password, but again allowing us (my son and I) to use the same iCloud & Itunes account? Does that make more sense??? I'm sincerely trying to get this cleared up once and for all----just need guidance from someone who has a true understanding of the whole Apple iCloud/Itunes system!
    Thanks again for "anyone" that can help me!!!

Maybe you are looking for