Get dates of last week - Please Help !

Hi All,
I have to make a query for retrieving the data for the last one week from a table say "Orderdata".
So can anybody please tell me how to retrieve date of last weak from the current date. I mean if current date is 12/08/2004 (mm/dd/yyyy) then I would be needing date as :--
12/01/2004 (mm/dd/yyyy) to 12/07/2004 (mm/dd/yyyy).
To more clear, here is the query that am using :
select * from orderdata where orderdate between 12/01/2004 AND 12/07/2004
I know I would be needing java.sql.timestamp class to set date . but it is the last thing to do .
First I have to get date of last weak...........
Here is the code----------that i have just start to write ..
Calendar cal;
TimeZone tz;
String estTimezone="GMT-05:00";
tz=TimeZone.getTimeZone(estTimezone);
cal=new GregorianCalendar(tz);
cal.setTimeZone(tz);
String currentdate=String.valueOf(cal.get(Calendar.MONTH)+1);
currentdate+="/"+String.valueOf(cal.get(Calendar.DAY_OF_MONTH)-1);
currentdate+="/"+String.valueOf(cal.get(Calendar.YEAR));
out.println(currentdate);And assume if current date is 12/1/2004 (mm/dd/yyyy) then subtracting -1 form the current date will give 12/00/2004 so not getting the correct result .
Hope it is clear to all................
Please Help !
amitindia

Hi All,
Thanks chirag813 for your coding. and thanks to all.
By the way I have to change time in EST and also required start date and end date of last weak. So my final coding is as:
Please have a look into the code and tell me whether the code is correct / fine or not.
Do I need to call the getInstance() method in my code as you (chirag813) have put in your code
Calendar calendar = Calendar.getInstance();
Is my code fine ?
Please Answer..................
String startdate;
String enddate;
Calendar cal;
TimeZone tz;
String estTimezone="GMT-05:00";
// is this line correct to get startdate
SimpleDateFormat sdfStartdate= new SimpleDateFormat("yyyy-MM-dd 00:00:00");
// is this line correct to get enddate
SimpleDateFormat sdfEnddate= new SimpleDateFormat("yyyy-MM-dd 23:59:59");
tz=TimeZone.getTimeZone(estTimezone);
cal=new GregorianCalendar(tz);
cal.setTimeZone(tz);
cal.add(Calendar.DATE,-7);
startdate=sdfStartdate.format(cal.getTime());
cal.add(Calendar.DATE,6);
enddate=sdfEnddate.format(cal.getTime());
Timestamp t1=Timestamp.valueOf(startdate);
Timestamp t2=Timestamp.valueOf(enddate);
out.println(t1);
out.println("<br>"+t2);
And finally I have used Timestamp class to change the date (String) to Timestampt.
Thanks !
amitindia
SCJP 1.2

Similar Messages

  • Calculate Dates for Last week and next three weeks

    Hi,
    I have a report where I need to calculate dates between last week and the next three weeks (not counting current week). I'm familar with the first part, it could be done by using the LastFullweek function but not sure how I can avoid the current week and calculate the next three weeks.
    Any help is greatly appreciated.
    Thanks!

    ... and here are a few more...
    Last Week...
    IF {TableName.Date} IN
    DateAdd("ww", DateDiff("ww", #1/7/1900#, CurrentDate), #1/7/1900#)
    To
    DateAdd("ww", DateDiff("ww", #1/7/1900#, CurrentDate) -1, #1/7/1900#)
    THEN TRUE ELSE FALSE
    The week before...
    IF {TableName.Date} IN
    DateAdd("ww", DateDiff("ww", #1/7/1900#, CurrentDate) -1, #1/7/1900#)
    To
    DateAdd("ww", DateDiff("ww", #1/7/1900#, CurrentDate) -2, #1/7/1900#)
    THEN TRUE ELSE FALSE
    And the week before that...
    IF {TableName.Date} IN
    DateAdd("ww", DateDiff("ww", #1/7/1900#, CurrentDate) -2, #1/7/1900#)
    To
    DateAdd("ww", DateDiff("ww", #1/7/1900#, CurrentDate) -3, #1/7/1900#)
    THEN TRUE ELSE FALSE
    and of course all 3 weeks together...
    IF {TableName.Date} IN
    DateAdd("ww", DateDiff("ww", #1/7/1900#, CurrentDate), #1/7/1900#)
    To
    DateAdd("ww", DateDiff("ww", #1/7/1900#, CurrentDate) -3, #1/7/1900#)
    THEN TRUE ELSE FALSE
    If you want the 1st day of the week to be Monday instead of Sunday just change the date of #1/7/190# to #1/1/1900#
    HTH,
    Jason

  • I logged onto my MacBook Air and it is asking me for my "local items" keychain password for several different things. I do not know what this is or how to get rid of it. Please help. Thanks.

    I logged onto my MacBook Air and it is asking me for my "local items" keychain password for several different things. I do not know what this is or how to get rid of it. Please help. Thanks.

    There are several possible causes for this issue. Please take each of the following steps that you haven't already tried, testing after each one, until it's resolved. Back up all data before making any changes.
    Step 1
    Follow the directions in this support article.
    Step 2
    Open the iCloud preference pane and uncheck the Keychain box. You'll be prompted to delete the local iCloud keychain. Confirm. Then re-check the box. Follow one of the procedures described in this support article to set up iCloud Keychain on an additional device.
    Step 3
    Open the Keychains folder as in Step 1. There should be a file in that folder with the name "login.keychain". If there is also a file iwith the name "login_renamed_1.keychain", then please do as follows:
    Rename login.keychain to "login-old.keychain".
    Rename login_renamed_1.keychain to "login.keychain".
    You can then close the folder.
    Launch the Keychain Access application in any of the following ways:
    ☞ Enter the first few letters of its name into a Spotlight search. Select it in the results (it should be at the top.)
    ☞ In the Finder, select Go ▹ Utilities from the menu bar, or press the key combination shift-command-U. The application is in the folder that opens.
    ☞ Open LaunchPad. Click Utilities, then Keychain Access in the icon grid.
    Delete the login keychain from the keychain list. Choose Delete References when prompted, not Delete References & Files.
    Select
    File ▹ Add Keychain...
    from the menu bar. Add back the file now named "login.keychain". If any of your needed keychain items are missing from it, also add back the file now named "login-old.keychain". I suggest you transfer any needed items from that keychain to the login keychain, then delete it. The transfers are made by drag-and-drop in Keychain Access. You'll need to enter your password for each item transferred.
    Select
    Keychain Access ▹ Keychain First Aid
    from the menu bar and repair the keychain. Quit Keychain Access.

  • My App Store won't allow me to download any apps. It says such and such app is unable to download try again later  every time. I have enough storage all my devices are up to date on all updates  please help

    My App Store won't allow me to download any apps. It says such and such app is unable to download try again later  every time. I have enough storage all my devices are up to date on all updates  please help

    I am a librarian at a 1:1 iPad school and we are having this problem with all ~3000 student iPads as well at ~300 teacher iPads.  This is extremely frustrating.  I have tried suggested fixes found on other discussion boards but none have worked.

  • ITunes wont open for me. it keeps saying "the Disc "untitled playlist" cannot be read. An unknown error occurred (-69)." don't know how to get it to work. Please help

    iTunes wont open for me. it keeps saying "the Disc "untitled playlist" cannot be read. An unknown error occurred (-69)." don't know how to get it to work. Please help

    It is likely a hardware failure
    http://support.apple.com/kb/TS3694?viewlocale=en_US#error1

  • When trying to verify the email address, I get the following message. Please help. This email address is already in use or you may already have an Apple ID associated with this email address. Please try again or sign in using your existing Apple ID.

    When trying to verify the email address, I get the following message. Please help. This email address is already in use or you may already have an Apple ID associated with this email address. Please try again or sign in using your existing Apple ID.

    Me too. I try to verify and i get the same message.
    I've created 3 alternate e-mail addresses and tried creating new accounts.
    Same Result!
    This is bullsh!t. How the **** can all 4 of my attempts result in the same freakin error???

  • I bought iPhone 4 for my wife, didn't create a separate apple ID account for her at that time. How can I now create a new one for her, sync her phone to the same PC that I sync my iPhone with without loosing all of her data, contacts, etc. Please help!

    I bought iPhone 4 for my wife, didn't create a separate apple ID account for her at that time. How can I now create a new one for her, sync her phone to the same PC that I sync my iPhone with without loosing all of her data, contacts, etc. Please help!

    I bought iPhone 4 for my wife, didn't create a separate apple ID account for her at that time. How can I now create a new one for her, sync her phone to the same PC that I sync my iPhone with without loosing all of her data, contacts, etc. Please help!

  • I down loaded about 100 cds to my library and I can no longer view the downloaded artwork it's shows a black picture or blank. How can I get the artwork back? Please help! Thank you

    I downloaded about 100 cds to my library and I can no longer view the downloaded artwork it's shows a black picture or blank. How can I get the artwork back? Please help! Thank you.

    Hi- apparently I also had a similar moment of madness and thought that 'freeride games' would be fun. Well, so much for that! It added a ton of things to my tool bar, I would like to uninstall it, any suggestions for this one?
    thanks :)

  • I need to pass a query in form of string to DBMS_XMLQUERY.GETXML package...the parameters to the query are date and varchar ..please help me..

    I need to pass a query in form of string to DBMS_XMLQUERY.GETXML package...the parameters to the query are date and varchar ..please help me build the string .Below is the query and the out put. ( the string is building fine except the parameters are with out quotes)
    here is the procedure
    create or replace
    procedure temp(
        P_MTR_ID VARCHAR2,
        P_FROM_DATE    IN DATE ,
        P_THROUGH_DATE IN DATE ) AS
        L_XML CLOB;
        l_query VARCHAR2(2000);
    BEGIN
    l_query:=  'SELECT
        a.s_datetime DATETIME,
        a.downdate Ending_date,
        a.downtime Ending_time,
        TO_CHAR(ROUND(a.downusage,3),''9999999.000'') kWh_Usage,
        TO_CHAR(ROUND(a.downcost,2),''$9,999,999.00'') kWh_cost,
        TO_CHAR(ROUND(B.DOWNUSAGE,3),''9999999.000'') KVARH
      FROM
        (SELECT s_datetime + .000011574 s_datetime,
          TO_CHAR(S_DATETIME ,''mm/dd/yyyy'') DOWNDATE,
          DECODE(TO_CHAR(s_datetime+.000011574 ,''hh24:'
          ||'mi''), ''00:'
          ||'00'',''24:'
          ||'00'', TO_CHAR(s_datetime+.000011574,''hh24:'
          ||'mi'')) downtime,
          s_usage downusage,
          s_cost downcost
        FROM summary_qtrhour
        WHERE s_mtrid = '
        ||P_MTR_ID||
       ' AND s_mtrch   = ''1''
        AND s_datetime BETWEEN TO_DATE('
        ||P_FROM_DATE||
        ',''DD-MON-YY'') AND (TO_DATE('
        ||P_THROUGH_DATE||
        ',''DD-MON-YY'') + 1)
        ) a,
        (SELECT s_datetime + .000011574 s_datetime,
          s_usage downusage
        FROM summary_qtrhour
        WHERE s_mtrid = '
        ||P_MTR_ID||
        ' AND s_mtrch   = ''2''
        AND s_datetime BETWEEN TO_DATE('
        ||P_FROM_DATE||
        ',''DD-MON-YY'') AND (TO_DATE('
        ||P_THROUGH_DATE||
        ','' DD-MON-YY'') + 1)
        ) B
      where a.S_DATETIME = B.S_DATETIME(+)';
    SELECT DBMS_XMLQUERY.GETXML('L_QUERY') INTO L_XML   FROM DUAL;
    INSERT INTO NK VALUES (L_XML);
    DBMS_OUTPUT.PUT_LINE('L_QUERY IS :'||L_QUERY);
    END;
    OUTPUT parameters are in bold (the issue is they are coming without single quotes otherwise th equery is fine
    L_QUERY IS :SELECT
        a.s_datetime DATETIME,
        a.downdate Ending_date,
        a.downtime Ending_time,
        TO_CHAR(ROUND(a.downusage,3),'9999999.000') kWh_Usage,
        TO_CHAR(ROUND(a.downcost,2),'$9,999,999.00') kWh_cost,
        TO_CHAR(ROUND(B.DOWNUSAGE,3),'9999999.000') KVARH
      FROM
        (SELECT s_datetime + .000011574 s_datetime,
          TO_CHAR(S_DATETIME ,'mm/dd/yyyy') DOWNDATE,
          DECODE(TO_CHAR(s_datetime+.000011574 ,'hh24:mi'), '00:00','24:00', TO_CHAR(s_datetime+.000011574,'hh24:mi')) downtime,
          s_usage downusage,
          s_cost downcost
        FROM summary_qtrhour
        WHERE s_mtrid = N3165 AND s_mtrch   = '1'
        AND s_datetime BETWEEN TO_DATE(01-JAN-13,'DD-MON-YY') AND (TO_DATE(31-JAN-13,'DD-MON-YY') + 1)
        ) a,
        (SELECT s_datetime + .000011574 s_datetime,
          s_usage downusage
        FROM summary_qtrhour
        WHERE s_mtrid = N3165 AND s_mtrch   = '2'
        AND s_datetime BETWEEN TO_DATE(01-JAN-13,'DD-MON-YY') AND (TO_DATE(31-JAN-13,' DD-MON-YY') + 1)
        ) B
      where a.S_DATETIME = B.S_DATETIME(+)

    The correct way to handle this is to use bind variables.
    And use DBMS_XMLGEN instead of DBMS_XMLQUERY :
    create or replace procedure temp (
      p_mtr_id       in varchar2
    , p_from_date    in date
    , p_through_date in date
    is
      l_xml   CLOB;
      l_query VARCHAR2(2000);
      l_ctx   dbms_xmlgen.ctxHandle;
    begin
      l_query:=  'SELECT
        a.s_datetime DATETIME,
        a.downdate Ending_date,
        a.downtime Ending_time,
        TO_CHAR(ROUND(a.downusage,3),''9999999.000'') kWh_Usage,
        TO_CHAR(ROUND(a.downcost,2),''$9,999,999.00'') kWh_cost,
        TO_CHAR(ROUND(B.DOWNUSAGE,3),''9999999.000'') KVARH
      FROM
        (SELECT s_datetime + .000011574 s_datetime,
          TO_CHAR(S_DATETIME ,''mm/dd/yyyy'') DOWNDATE,
          DECODE(TO_CHAR(s_datetime+.000011574 ,''hh24:'
          ||'mi''), ''00:'
          ||'00'',''24:'
          ||'00'', TO_CHAR(s_datetime+.000011574,''hh24:'
          ||'mi'')) downtime,
          s_usage downusage,
          s_cost downcost
        FROM summary_qtrhour
        WHERE s_mtrid = :P_MTR_ID
        AND s_mtrch   = ''1''
        AND s_datetime BETWEEN TO_DATE(:P_FROM_DATE,''DD-MON-YY'')
                           AND (TO_DATE(:P_THROUGH_DATE,''DD-MON-YY'') + 1)
        ) a,
        (SELECT s_datetime + .000011574 s_datetime,
          s_usage downusage
        FROM summary_qtrhour
        WHERE s_mtrid = :P_MTR_ID
        AND s_mtrch   = ''2''
        AND s_datetime BETWEEN TO_DATE(:P_FROM_DATE,''DD-MON-YY'')
                           AND (TO_DATE(:P_THROUGH_DATE,'' DD-MON-YY'') + 1)
        ) B
      where a.S_DATETIME = B.S_DATETIME(+)';
      l_ctx := dbms_xmlgen.newContext(l_query);
      dbms_xmlgen.setBindValue(l_ctx, 'P_MTR_ID', p_mtr_id);
      dbms_xmlgen.setBindValue(l_ctx, 'P_FROM_DATE', to_char(p_from_date, 'DD-MON-YY'));
      dbms_xmlgen.setBindValue(l_ctx, 'P_THROUGH_DATE', to_char(p_through_date, 'DD-MON-YY'));
      l_xml := dbms_xmlgen.getXML(l_ctx);
      dbms_xmlgen.closeContext(l_ctx);
      insert into nk values (l_xml);
    end;

  • Hi, i have a A1186 Mac Pro 2008 Tower. Im running windows 7 64Bit on it. Im not sure about what version of bootcamp should i use to get the drivers. Someone please help me.

    Hi, i have a A1186 Mac Pro 2008 Tower. Im running windows 7 64Bit on it. Im not sure about what version of bootcamp should i use to get the drivers. Someone please help me.

    Boot Camp support:
    http://www.apple.com/support/bootcamp/
    Boot Camp FAQ:
    http://support.apple.com/kb/HT5639?viewlocale=en_US

  • I have iTunes 11.1.3 and when I click on iTunes Store in the top right corner I just get a blank screen. Please help me! I want to buy music!

    I have iTunes 11.1.3 and when I click on iTunes Store in the top right corner I just get a blank screen. Please help me! I want to buy music!

    Hi, iTunes Store Help 12. 
    Thank you for visiting Apple Support Communities. 
    Here is an article I would recommend going through when experiencing issues with the iTunes Store. 
    iTunes: Advanced iTunes Store troubleshooting
    http://support.apple.com/kb/ts3297
    Cheers,
    Jason H. 

  • Security question keep saying they are wrong and I know they are right. I can't change them cuz when I try it tells me to answer the questions. I have tried everything changing my account and all and still can't get it can some one please help me out.

    Security question keep saying they are wrong and I know they are right. I can't change them cuz when I try it tells me to answer the questions. I have tried everything changing my account and all and still can't get it can some one please help me out.

    Go here and select "Reset your password."  You will receive an email message with a link that bypasses the questions.  You will then be able to select and answer the questions again.

  • To open "Java Preferences," you need to install a Java runtime, but you are not connected to the Internet. I have tried links that people have put on other discussions but all i get is a black screen please help!!

    To open “Java Preferences,” you need to install a Java runtime, but you are not connected to the Internet. I have tried links that people have put on other discussions but all i get is a black screen please help!!

    Try this link, warning, it's straight to download mode:
    http://support.apple.com/downloads/DL1421/en_US/JavaForMacOSX10.7.dmg

  • I have a problem in the data entry Visa card please help

    I have a problem in the data entry Visa card please help

    abdulaziz711 wrote:
    I have a problem in the data entry Visa card please help
    Is this what you mean...
    http://support.apple.com/kb/TS1646
    If no joy...
    Contact iTunes Customer Service and request assistance
    Use this Link  >  Apple  Support  iTunes Store  Contact

  • I want to check the main diffrence in Pop up block enabled and disabled.But,i don't get any difference.Would u please help me to understand the difference using one practical example of website

    I want to check the main diffrence in Pop up block enabled and disabled.But,i don't get any difference.Would u please help me to understand the difference using one practical example of website

    Here's two popup test sites.
    http://www.kephyr.com/popupkillertest/test/index.html
    http://www.popuptest.com/

Maybe you are looking for

  • Report Wizard - Inconsistency causing ORA-01461 - bind a LONG (bug?)

    We have come across an inconsistency in the creation of APEX report region resulting in an error "ORA-01461: can bind a LONG value only for insert into a LONG column" I want to share this to either get the attention of someone on the development team

  • "Cells too small to split". As per usual.

    Every year or so, while experimenting with XML, I am suddenly reminded of why I never use tables and XML together. Unless you have XML that explicitly specifies the formatting (column width and so on, using attributes of a specially dedicated namespa

  • ADF BC : Problem in Inserting a Master - Detail Record

    Hi, I am new to ADF Business Components. I am into a project where i use only the ADF BC as ORM/DB Operations and for the front end I use some other framework. The Problem is. I have two entity objects and a ViewLink between them. [Relation between "

  • Query from DUAL

    I am calling a Pl/sql function in a select query which has a statement as below SELECT SUBSTR(5/2,2,1) INTO m_delim FROM DUAL; The number of records returned from the calling select query is more 1 million. How much adversly the query from DUAL table

  • NullPointerException-Problem

    Why do I get a NullPointerException from this code? The code should write �Test� in an applet. import java.applet.*; import java.awt.*; public class fot extends Applet {           myCanvas bild;      public void init(){      setLayout(new BorderLayou