Link to home
Start Free TrialLog in
Avatar of modish
modish

asked on

get max date record entered in previous month

Hello
I have a table where I extract data for a given day - I want to compare this data with data from previous month - but only the data for the last entry for the previous month - how would I do this?

ASKER CERTIFIED SOLUTION
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of modish
modish

ASKER

Apologies for the late response
thanks to you both for your responses - I couldn't get aneeshattingals one to work  problem with casting.- but angelIII worked brilliantly -
I changed it to be
 yourfield <= dateadd(day,  - datepart(day, getdate()), convert(datetime, convert(varchar(10), getdate(), 120), 120) )  
to get the last day of the previous month ..
Is this the best way to do the same for the month before that.
yourfield <=  dateadd(month,-1,dateadd(day, 1 - datepart(day, getdate()), convert(datetime, convert(varchar(10), getdate(), 120), 120) )   )

yes. the dateadd(month, -1) ... will take care of any 31/30/29/28 days per month.
Avatar of modish

ASKER

Excellent and aneeshattingal solution worked as well :-)