15 pts.
 DATETIME calculation
Hi there, this is probably very simple but i just can't get it working. I want to subtract one month from a variable month. So if the datetime variable is equal to 10 Feb 2008 the result should be 10 Jan 2008. Please help. Thanks

Software/Hardware used:
ASKED: April 1, 2008  6:38 AM
UPDATED: April 1, 2008  1:52 PM

Answer Wiki:
You did not mention which database system you're using, and this is an important item of information, as all of them seem to have a different set of date functions. The <b>standard SQL </b> way of doing it is with [i]intervals[/i] -- SELECT foo FROM bar WHERE datecolumn = CURRENT_DATE - INTERVAL 1 MONTH MySQL supports this, as do several others. In Microsoft SQL Server, you have to use the proprietary GETDATE and DATEADD functions -- SELECT foo FROM bar WHERE datecolumn = DATEADD(MONTH,-1,GETDATE())
Last Wiki Answer Submitted:  April 1, 2008  1:52 pm  by  RudyLimeback   440 pts.
All Answer Wiki Contributors:  RudyLimeback   440 pts.
To see all answers submitted to the Answer Wiki: View Answer History.


Discuss This Question:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _