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

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

Posted on 2009-07-03
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 = "">
Select * from mytable where date between startdate and enddate

Open in new window

Question by:LeadCo
LVL 13

Accepted Solution

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 ) />
Week :<br>
#objcurrentWeek.Start# <br />
#objcurrentWeek.End#  <br>
<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)>
Month : <br>
#Dateformat(objcurrentMonth.Start,"dd/mmm/yyyy")# <br />
#Dateformat(objcurrentMonth.End,"dd/mmm/yyyy")#  <br>
<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)>
Year :<br>
#Dateformat(objcurrentYear.Start,"dd/mmm/yyyy")#<br />
#Dateformat(objcurrentYear.End,"dd/mmm/yyyy")# <br>
Wrote this code long back :)) , Hope this helps
 Let me know if you need more help in this

Author Closing Comment

ID: 31599723

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Hi. There are several upload tutorials using jquery and coldfusion. I found a very interesting one here Upload Your Files using Jquery & ColdFusion and Preview them (http://www.randhawaworld.com/) . I did keep the main js functions but made sever…
Sometimes databases have MILLIONS of records and we need a way to quickly query that table to return the results me need. Sure you could use CFQUERY but it takes too long when there are millions of records. That is why SOLR was invented. Please …
The purpose of this video is to demonstrate how to properly insert a Vimeo Video into a WordPress site or Blog. This will be demonstrated using a Windows 8 PC. Go to your WordPress login page. This will look like the following: mywebsite.com/wp…
The purpose of this video is to demonstrate how to reset a WordPress password if you are locked out and cannot reset the password. A typical use would be if you cannot access the email to which WordPress would send the password recovery email to…

860 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