Results 1 to 8 of 8
  1. #1
    Join Date
    Jan 2010
    Posts
    64

    Exclamation Unanswered: First and Last dates of prebvious month based on user input

    Hi,

    My sql will accept the date in (DD-MM-YYYY) format from the user and based on that i have
    to show two dates in the previous month i.e the start date and end date of the month

    For example : if user enters 04-06-2010 then my script should show two dates
    Start Date 01-05-2010 and End Date 31-05-2010
    : if user enters 04-01-2010 then my script should show two dates
    Start Date 01-12-2009 and End Date 31-12-2009

    Please advice !!!

    Cheers!
    Subhotech

  2. #2
    Join Date
    Aug 2003
    Location
    Where the Surf Meets the Turf @Del Mar, CA
    Posts
    7,776
    Provided Answers: 1
    ADD_MONTHS

    LAST_DAY

    realize that the 01 is always the first on any month
    You can lead some folks to knowledge, but you can not make them think.
    The average person thinks he's above average!
    For most folks, they don't know, what they don't know.
    Good judgement comes from experience. Experience comes from bad judgement.

  3. #3
    Join Date
    Jun 2008
    Location
    pakistan
    Posts
    109
    This is your total query dude enjoy....

    PHP Code:
    select add_months(trunc(sysdate,'month'),-1from dual

  4. #4
    Join Date
    Jun 2004
    Location
    Liverpool, NY USA
    Posts
    2,509
    Actually this is the query

    select add_months(trunc(sysdate,'month'),-1) first,
    last_day(add_months(trunc(sysdate,'month'),-1)) last
    from dual;
    Bill
    You do not need a parachute to skydive. You only need a parachute to skydive twice.

  5. #5
    Join Date
    Jun 2008
    Location
    pakistan
    Posts
    109
    Quote Originally Posted by beilstwh View Post
    Actually this is the query

    select add_months(trunc(sysdate,'month'),-1) first,
    last_day(add_months(trunc(sysdate,'month'),-1)) last
    from dual;
    agreed forgot to show last date thanks dude beilstwh

  6. #6
    Join Date
    Jan 2010
    Posts
    64

    one last help

    how to convert the final date into DD-MM-YYYY format. I tried TO_DATE function but got errors.

  7. #7
    Join Date
    Nov 2003
    Posts
    2,935
    Provided Answers: 12
    Quote Originally Posted by subhotech View Post
    how to convert the final date into DD-MM-YYYY format. I tried TO_DATE function but got errors.
    to_date() converts a character literal to a date.
    You want to convert a date to a character literal, therefor you have to use to_char()

  8. #8
    Join Date
    Jan 2010
    Posts
    64

    Thanks!! all for the help !!

    Thanks!! all for the help

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •