Solved

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

Posted on 2009-07-03
2
217 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 13

Accepted Solution

by:
srikanthmadishetti earned 500 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

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Fixing some Issues with regex again 9 41
Apache error.log 19 72
Can I put javascript code in my application.cfm file 4 55
How can i point a subdomain to directory? 5 38
When setting up new project requests for our site, one of the most powerful tools our team has available to use is Axure (http://www.axure.com/). It’s a tool for creating software and web prototypes that can function and interact as if it were the a…
Objective of This Article In 1990’s, when I was a budding software professional, I had a lot of confusion about which stream or technology, I had to choose to build my career. In those days, I had lot of confusion like whether to choose System so…
The purpose of this video is to demonstrate how to prevent comment spam on a WordPress Website. This will be demonstrated using a Windows 8 PC. Plugin Akismet will be used. Go to your WordPress login page. This will look like the following: myw…
The purpose of this video is to demonstrate how to set up basic WordPress SEO. This will be demonstrated using a Windows 8 PC. The plugin used will be WordPress SEO by Yoast. Go to your WordPress login page. This will look like the following: myw…

735 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