Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Last Month Date Range CFSET

Status
Not open for further replies.

3dColor

Programmer
Jan 10, 2006
240
0
0
US
I currently track a parameter from the first of the year and the first of the current month.

But I would also like to track all of last month.

Here is what I have so far that works - in the WHERE statement of the query.

Code:
<cfset today = CreateODBCDate(Now())>
<CFSET tektips = CreateDateTime(year(today), 1, 1, 0, 0, 0)>
<CFSET sinceThe1st = CreateDateTime(year(today), month(today), Day(tektips), hour(tektips), minute(tektips), second(tektips))>
<CFSET sinceThe1stOfTheYear = CreateDateTime(year(today), month(tektips), Day(tektips), hour(tektips), minute(tektips), second(tektips))>

How do I do one for last month with is a moving target?
 
Read up on the DateAdd function. Since you already have the first day of the current month, you can use it to determine the other values. To get the first of the previous month, just subtract one month.

<cfset firstOfPreviousMonth = dateAdd("m", -1, firstOfThisMonth)>

To get the last day of the previous month, subtract one day.

<cfset lastOfPreviousMonth = dateAdd("d", -1, firstOfThisMonth)>



----------------------------------
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top