www.webdeveloper.com
Results 1 to 3 of 3

Thread: [RESOLVED] Fetching Last Month Records-Need Clarification

  1. #1
    Join Date
    Dec 2010
    Posts
    39

    resolved [RESOLVED] Fetching Last Month Records-Need Clarification

    Hi Guys,

    I need one clarification.. i'm in a need to fetch all records from employee table(i.e last month record eg. if this month is May means i wanna fetch april month records.).. I hav used a mysql query(am using jsp)

    Query1 : select * from empadvanceamount where Date >= DATE_SUB(CURDATE(),INTERVAL 1 MONTH) and Empid=?
    if am using the above query means i cant able to fetch last month records..

    Query2: select * from empadvanceamount where Date between DATE_SUB(CURDATE(),INTERVAL 1 MONTH) and Empid=?
    but if am using the above query with 'between' means i can fetch records...

    Please explain me the difference ..as am newbie to this mysql....Thanks in advance....

    Daya.k

  2. #2
    Join Date
    May 2011
    Posts
    25
    if you want to fetch ALL the records of previous month then this will work better:

    PHP Code:
    select from empadvanceamount where
    MONTH
    (date) = MONTH(now() - INTERVAL 1 MONTH)
    AND
    YEAR(date) = YEAR(now() - INTERVAL 1 MONTH
    That way you will always fetch the first day till the last day of the previous month.

  3. #3
    Join Date
    Dec 2010
    Posts
    39

    Smile

    Thank u very much qrizly....thats very helpful.......

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles