Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How do you create dates for today, this week,this month and this year in cf8.

Posted on 2009-07-03
2
Medium Priority
?
223 Views
Last Modified: 2013-12-24
How do you create dates for today, this week,this month and this year in cf8.

My code:
Experts :
I have a variable called leadframe being passed via cfdiv bind from form element leadframe.
the options are: today, thisweek,thismonth,thisyear
I understand how to set the variables i just don't know how to calculate the values.
I want to set startdate to the calendar date to begin query and enddate to end query.



<cfif leadframe EQ "today">
    <cfset startdate = "">
    <cfset enddate = "">
<cfelseif leadframe EQ "thisWeek">
      <cfset startdate = "">
       <cfset enddate = "">
<cfelseif startdate EQ "ThisMonth">
   <cfset startdate = "">
   <cfset enddate = "">
<cfelseif leadframe EQ "ThisYear">
     <cfset startdate = "">
     <cfset enddate = "">
</cfif>
 
Query:
 
Select * from mytable where date between startdate and enddate

Open in new window

0
Comment
Question by:LeadCo
2 Comments
 
LVL 13

Accepted Solution

by:
srikanthmadishetti earned 2000 total points
ID: 24776590
For today keep the start and date coldfusion date fucntion now()
for all the other 3 here is the code:
 

<cfset dtcurrenttWeek = Fix( Now() )  />
                 
               
                <cfset objcurrentWeek = StructNew() />
                                <!--- Get start of week. --->
                <cfset objcurrentWeek.Start = DateFormat(dtcurrenttWeek - DayOfWeek( dtcurrenttWeek ) + 1
                ) />
                 
                <!--- Get end of week by adding to start date. --->
<cfset objcurrentWeek.End = DateFormat( objcurrentWeek.Start + 6 ) />
 
<cfoutput>
Week :<br>
#objcurrentWeek.Start# <br />
#objcurrentWeek.End#  <br>
</cfoutput>
 
 
<cfset objcurrentMonth = StructNew() />
 
 
<cfset yr=Year(Now())>
<cfset m=Month(Now())>
<cfset d=DaysInMonth(Now())>
<cfset objcurrentMonth.end=Createdate(#yr#,#m#,#d#)>
<cfset objcurrentMonth.start=Createdate(#yr#,#m#,01)>
 
<cfoutput>
Month : <br>
#Dateformat(objcurrentMonth.Start,"dd/mmm/yyyy")# <br />
#Dateformat(objcurrentMonth.End,"dd/mmm/yyyy")#  <br>
</cfoutput>
 
 
<cfset objcurrentYear = StructNew() />
 
 
<cfset yr=Year(Now())>
<cfset m=Month(Now())>
<cfset d=DaysInMonth(Now())>
<cfset objcurrentYear.end=Createdate(#yr#,01,01)>
<cfset objcurrentYear.start=Createdate(#yr#,12,31)>
 
<cfoutput>
Year :<br>
#Dateformat(objcurrentYear.Start,"dd/mmm/yyyy")#<br />
#Dateformat(objcurrentYear.End,"dd/mmm/yyyy")# <br>
</cfoutput>
 
 
Wrote this code long back :)) , Hope this helps
 Let me know if you need more help in this
0
 

Author Closing Comment

by:LeadCo
ID: 31599723
Thanks!
0

Featured Post

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article provides a case study on how our local youth baseball league deployed a new website, including the platform selection, implementation and benefits to the league.
Originally, this post was published on Monitis Blog, you can check it here . It goes without saying that technology has transformed society and the very nature of how we live, work, and communicate in ways that would’ve been incomprehensible 5 ye…
The purpose of this video is to demonstrate how to exclude a particular blog category from the main blog page. This is can be used when a category already has its own tab, or you simply want certain types of posts not to show up on the main blog. …
The purpose of this video is to demonstrate how to Test the speed of a WordPress Website. Site Speed is an important metric of a site’s health. Slow site speed can result in viewers leaving your site quickly and not seeing your content. This…

885 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question