Important alert: (current site time 7/16/2013 6:51:58 AM EDT)
 

VB icon

What was mondays date?

Email
Submitted on: 10/3/2001 4:02:49 PM
By: Tim Garver  
Level: Intermediate
User Rating: By 1 Users
Compatibility: Cold Fusion 4.5
Views: 10606
author picture
(About the author)
 
     This snippet of code will calculate this past mondays date. very usefull when querying a database with a dynamic date range.
 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
 
Terms of Agreement:   
By using this code, you agree to the following terms...   
  1. You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
  2. You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
  3. You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
  4. You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.
				
//**************************************
// Name: What was mondays date?
// Description:This snippet of code will calculate this past mondays date. very usefull when querying a database with a dynamic date range.
// By: Tim Garver
//
// Inputs:Todays date
//
// Returns:last mondays date and this fridays date as Dates in two variables called "mon" and "fri".
//
//This code is copyrighted and has// limited warranties.Please see http://www.Planet-Source-Code.com/vb/scripts/ShowCode.asp?txtCodeId=26&lngWId=9//for details.//**************************************

<!--- This section finds last mondays date and creates a variable called mon. --->	
<!--- To use this just paste this code to any CF page and call the variable mon. --->
<!--- This also finds Fridays date as well. And creates a variable for that date called fri. --->
<!--- This section is for testing different date possibilities. Change to a date you want to test from. --->
<cfset test = createdate(year(now()),month(now()),day(now()))>
<!--- End Test area --->
<!--- Sets up todays ordinal number --->
<cfset todaysnum = #dayofweek(test)#>
<!--- End --->
<!--- The IF statement checks to see what today is. --->
<!--- IF today is Tue thru Sat or (3 thru 7) --->
<cfif #todaysnum# GTE "3">
<!--- Today is Tuesday thru Saturday --->
<cfset start = (#dayofweek(test)# -2)>
<cfset str = (#day(test)# - start)>
<cfset mon = createdate(year(now()),month(now()),str)>
<cfset fri = #dateadd('d',4,mon)#>
<!--- End Tuesday thru Saturday --->
<cfelseif #todaysnum# EQ "2">
<!--- Today is Monday. So set mon to todays date. --->
<cfset mon = #test#>
<cfset fri = #dateadd('d',4,mon)#>
<!--- End Monday --->
<cfelseif #todaysnum# EQ "1">
<!--- Today is Sunday so lets look at last weeks Monday And Friday dates. --->
<cfset mon = #dateadd('d',-6,test)#>
<cfset fri = #dateadd('d',4,mon)#>
</cfif>
<!--- Ok were done. Lets output the dates. --->
This past Mondays date was <cfoutput>#dateformat(mon,'mm/dd/yyyy')#</cfoutput><br>
And Fridays date is <cfoutput>#dateformat(fri,'mm/dd/yyyy')#</cfoutput><br>


Other 11 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Intermediate category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments

 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.