Skip to main content

Posts

Showing posts with the label date

How to get quarter number from a date object in ColdFusion

Quarter() - get quarter number from a date object Quarter.cfm <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Quarter function example: how to get quarter number from a date object</title> </head> <body> <h2 style="color:hotpink">Quarter Function Example</h2> <cfset MyDate=DateFormat(Now())> <cfoutput> <b> MyDate: #MyDate# <br /> Quarter Number[MyDate]: #Quarter(MyDate)# </b> </cfoutput> </body> </html> More ColdFusion examples CreateTimeSpan() - create a time span DateAdd() - add year, quarter, month, week, day, hour, minute, second to a date DateCompare() - compare two date time object DateDiff() - get difference between two date time object DateFormat() - format a date value using U.S. date format MonthAsString() - get th...

How to get the month name from a month number in ColdFusion

MonthAsString() - get the month name from a month number MonthAsString.cfm <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>MonthAsString function example: how to get the month name from a month number</title> </head> <body> <h2 style="color:hotpink">MonthAsString Function Example</h2> <cfoutput> <b> Now: #Now()# <br /> Month Name: #MonthAsString(Month(Now()))# </b> </cfoutput> </body> </html> More ColdFusion examples DayOfYear() - get the day of the year in a Date DaysInMonth() - get the number of days in a month Hour() - get the current hour of the day IsDate() - check a string, is it date object or not Month() - get the month value from a date time object Quarter() - get quarter number from a date object

How to get the month value from a date time object in ColdFusion

Month() - get the month value from a date time object Month.cfm <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Month function example: how to get the month value from a date time object</title> </head> <body> <h2 style="color:hotpink">Month Function Example</h2> <cfoutput> <b> Now: #Now()# <br /> Month Number: #Month(Now())# </b> </cfoutput> </body> </html> More ColdFusion examples CreateDate() - create a date object DateCompare() - compare two date time object DatePart() - get a part from a date value DayOfYear() - get the day of the year in a Date Hour() - get the current hour of the day IsDate() - check a string, is it date object or not

How to check string, is it date object or not in ColdFusion

IsDate() - check a string, is it date object or not IsDate.cfm <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>IsDate function example: how to check string, is it date object or not</title> </head> <body> <h2 style="color:hotpink">IsDate Function Example</h2> <cfset ToDay=DateFormat(Now())> <cfset Myname="Jones"> <cfoutput> <b> ToDay: #ToDay# <br /> MyName: #MyName# <br /><br /> </b> </cfoutput> <table style="color:LightGreen; background:Green;" border="1" bordercolor="DarkGreen"> <tr> <td style="font-weight:bold">IsDate</td> <td style="font-weight:bold">Output</td> </tr> <tr> <td>#IsDate(ToDa...

How to get the current hour of the day in ColdFusion

Hour() - get the current hour of the day Hour.cfm <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Hour function example: how to get the current hour of the day</title> </head> <body> <h2 style="color:hotpink">Hour Function Example</h2> <cfoutput> <b> Now: #Now()# <br /> Current Hour: #Hour(Now())# </b> </cfoutput> </body> </html> More ColdFusion examples DayOfYear() - get the day of the year in a Date DaysInMonth() - get the number of days in a month GetTickCount() - get the system time in milliseconds GetTimeZoneInfo() - get local time zone information from caller computer

How to get local time zone information from caller computer in ColdFusion

GetTimeZoneInfo() - get local time zone information from caller computer GetTimeZoneInfo.cfm <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>GetTimeZoneInfo function example: how to get local time zone information from caller computer</title> </head> <body> <h2 style="color:hotpink">GetTimeZoneInfo Function Example</h2> <cfset LocalTimeZoneInfo=GetTimeZoneInfo()> <cfdump var="#LocalTimeZoneInfo#" label="Local Time Zone Information[Caller Computer]"> </body> </html> More ColdFusion examples GetTickCount() - get the system time in milliseconds Hour() - get the current hour of the day MonthAsString() - get the month name from a month number Quarter() - get quarter number from a date object

How to get the system time in milliseconds in ColdFusion

GetTickCount() - get the system time in milliseconds GetTickCount.cfm <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>GetTickCount function example: how to get the system time in milliseconds</title> </head> <body> <h2 style="color:hotpink">GetTickCount Function Example</h2> <cfset StartTick=GetTickCount()> <cfoutput><b>StartTick: #StartTick#</b></cfoutput> <br /><br /> Loop start...[1-1000000] <br /> <cfloop index="i" from="1" to="1000000" step="1"> </cfloop> Loop end... <br /><br /> <cfset EndTick=GetTickCount()> <cfoutput><b>EndTick: #EndTick#</b></cfoutput> <br /><br /> Loop Time: <cfoutput>#StartTick-EndTick# millisecond...

How to get the number of days in a month in ColdFusion

DaysInMonth() - get the number of days in a month DaysInMonth.cfm <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>DaysInMonth function example: how to get the number of days in a month</title> </head> <body> <h2 style="color:hotpink">DaysInMonth Function Example</h2> <cfset ToDay=DateFormat(Now(),"dd-mmm-yyyy")> <cfoutput> <b> Today: #Today# <br /> Number of days in this month: #DaysInMonth(ToDay)# </b> </cfoutput> </body> </html> More ColdFusion examples DayOfWeek() - get the day of the week in a Date DayOfWeekAsString() - get the day of the week, in a Date, as a string DayOfYear() - get the day of the year in a Date GetTickCount() - get the system time in milliseconds GetTimeZoneInfo() - get local time zone informa...

How to get the day of the year in a Date in ColdFusion

DayOfYear() - get the day of the year in a Date DayOfYear.cfm <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>DayOfYear function example: how to get the day of the year in a Date</title> </head> <body> <h2 style="color:hotpink">DayOfYear Function Example</h2> <cfset ToDay=DateFormat(Now())> <cfoutput> <b> Today: #Today# <br /> ToDay[day of the year]: #DayOfYear(ToDay)# </b> </cfoutput> </body> </html> More ColdFusion examples DatePart() - get a part from a date value DayOfWeek() - get the day of the week in a Date DayOfWeekAsString() - get the day of the week, in a Date, as a string DaysInMonth() - get the number of days in a month

How to get the day of the week, in a Date, as a string in ColdFusion

DayOfWeekAsString() - get the day of the week, in a Date, as a string DayOfWeekAsString.cfm <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>DayOfWeekAsString function example: how to get the day of the week, in a Date, as a string</title> </head> <body> <h2 style="color:hotpink">DayOfWeekAsString Function Example</h2> <cfset ToDay=DateFormat(Now())> <cfoutput> <b> Today: #Today# <br /> ToDay[day of the week as string]: #DayOfWeekAsString(DayOfWeek(ToDay))# </b> </cfoutput> </body> </html> More ColdFusion examples DatePart() - get a part from a date value DayOfWeek() - get the day of the week in a Date MonthAsString() - get the month name from a month number Quarter() - get quarter number from a date object

How to get the day of the week in a Date in ColdFusion

DayOfWeek() - get the day of the week in a Date DayOfWeek.cfm <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>DayOfWeek function example: how to get the day of the week in a Date</title> </head> <body> <h2 style="color:hotpink">DayOfWeek Function Example</h2> <cfset ToDay=DateFormat(Now())> <cfoutput> <b> Today: #Today# <br /> ToDay[day of the week]: #DayOfWeek(ToDay)# </b> </cfoutput> </body> </html> More ColdFusion examples DateCompare() - compare two date time object DateDiff() - get difference between two date time object DateFormat() - format a date value using U.S. date format DatePart() - get a part from a date value DayOfWeekAsString() - get the day of the week, in a Date, as a string DaysInMonth() - get the number o...

How to get a part from a date value in ColdFusion

DatePart() - get a part from a date value DatePart.cfm <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>DatePart function example: how to get a part from a date value</title> </head> <body> <h2 style="color:hotpink">DatePart Function Example</h2> <cfset MyDate=Now()> <cfoutput> <b> MyDate: #MyDate# <br /><br /> </b> </cfoutput> <table style="color:LightGreen; background:Green;" border="1" bordercolor="DarkGreen"> <tr> <td style="font-weight:bold">DatePart</td> <td style="font-weight:bold"></td> <td style="font-weight:bold">Output</td> </tr> <tr> <td>#DatePart("yyyy",MyDate)#</...

How to format a date value using U.S. date format in ColdFusion

DateFormat() - format a date value using U.S. date format DateFormat.cfm <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>DateFormat function example: how to format a date value using U.S. date format</title> </head> <body> <h2 style="color:hotpink">DateFormat Function Example</h2> <cfset MyDate=Now()> <cfoutput> <b> MyDate: #MyDate# <br /><br /> </b> </cfoutput> <table style="color:LightGreen; background:Green;" border="1" bordercolor="DarkGreen"> <tr> <td style="font-weight:bold">DateFormat</td> <td style="font-weight:bold"></td> <td style="font-weight:bold">Output</td> </tr> <tr> <td>#D...

How to get difference between two date time object in ColdFusion

Introduction In ColdFusion, working with dates is a frequent task in web development. One of the common requirements is calculating the difference between two date-time objects. ColdFusion provides a built-in function, DateDiff() , which simplifies this process by returning the difference between two dates in a specified date part (e.g., years, months, or days). This article breaks down an example where we use the DateDiff() function to compare two dates and display their differences in various units, including years, quarters, months, and days. The purpose of this tutorial is to demonstrate how to work with the DateDiff() function in ColdFusion and explore how it can be used to calculate differences between date objects efficiently. We’ll cover how the function works, and how the results are presented in an HTML table format. Setting Date Variables The first part of the code involves setting two date variables, MyDate and MyAnotherDate . These variables store two different dates: D...

How to compare two date time objects in ColdFusion

Introduction In ColdFusion, comparing dates is a common task, especially when determining whether one date occurs before, after, or exactly on the same day as another. This example demonstrates the use of ColdFusion's DateCompare function to easily compare two date-time objects and return results based on the comparison. DateCompare is a powerful utility in ColdFusion, especially when handling scheduling tasks, date-based validations, or any logic where date comparison is crucial. In this article, we’ll break down the code provided, showing how it sets up and uses the DateCompare function to output different results based on various date comparisons. Setting Up the Date Variables The code begins by defining two date variables, MyDate and MyAnotherDate , using the cfset tag. These variables represent two different dates that we’ll be comparing. The first MyDate is set to “3-Dec-2008,” while MyAnotherDate is set to “5-Dec-2008.” By using specific date formats, ColdFusion is ab...

ColdFusion DateAdd() - How to add year, quarter, month, week, day, hour, minute, second to a date

DateAdd() - add year, quarter, month, week, day, hour, minute, second to a date DateAdd.cfm <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>DateAdd function example: how to add year, quarter, month, week, day, hour, minute, second to a date</title> </head> <body> <h2 style="color:hotpink">DateAdd Function Example</h2> <cfset MyDateTime=Now()> <cfoutput> <b> MyDateTime: #MyDateTime# <br /> MyDateTime: #DateFormat(MyDateTime)# </b> <br /><br /> </cfoutput> <table style="color:LightGreen; background:Green;" border="1" bordercolor="DarkGreen"> <tr> <td style="font-weight:bold">DateAdd</td> <td style="font-weight:bold">DatePart</td> <td ...

How to create a time span in ColdFusion

CreateTimeSpan() - create a time span CreateTimeSpan.cfm <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>CreateTimeSpan function example: how to create a time span</title> </head> <body> <h2 style="color:hotpink">CreateTimeSpan Function Example</h2> <cfquery name="qEmployee" datasource="cfdocexamples" cachedwithin="#CreateTimeSpan(0,0,30,0)#" result="Employee"> SELECT Emp_ID, FirstName, LastName FROM EMPLOYEE </cfquery> <cfdump var="#Employee#"> <br /> <b>Query result catched for 30 minute TimeSpan</b> </body> </html> More ColdFusion examples CreateDate() - create a date object DateAdd() - add year, quarter, month, week, day, hour, minute, second to a date DateDiff() - get diff...

How to create an ODBC date time object in ColdFusion

CreateODBCDateTime() - create an ODBC date time object CreateODBCDateTime.cfm <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>CreateODBCDateTime function example: how to create an ODBC date time object</title> </head> <body> <h2 style="color:hotpink">CreateODBCDateTime Function Example</h2> <cfset MyDateTime="10-Feb-2008 03:06:09"> <cfset MyAnotherDateTime="5-Dec-2007 00:01:01"> <cfset MyODBCDateTime=CreateODBCDateTime(MyDateTime)> <cfset MyAnotherODBCDateTime=CreateODBCDateTime(MyAnotherDateTime)> <cfoutput> <b> MyDateTime: #MyDateTime# <br /> MyODBCDateTime: #MyODBCDateTime# <br /><br /> MyAnotherDateTime: #myAnotherDateTime# <br /> MyAnotherODBCDateTime: #myAnotherODBCDateTime# </b> </cfoutput...

How to create a date time object in ColdFusion

CreateDateTime() - create a date time object CreateDateTime.cfm <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>CreateDateTime function example: how to create a date time object</title> </head> <body> <h2 style="color:hotpink">CreateDateTime Function Example</h2> <cfset Year="2008"> <cfset Month="12"> <cfset Day="5"> <cfset Hour="6"> <cfset Minute="30"> <cfset Second="29"> <cfset CreatedDateTime=CreateDateTime(Year,Month,Day,Hour,Minute,Second)> <cfoutput> <b> Year: #Year# <br /> Month: #Month# <br /> Day: #Day# <br /> Hour: #Hour# <br /> Minute: #Minute# <br /> Second: #Second# <br /><br /> Created DateTime: #CreatedDateTime# </...

How to create a date object in ColdFusion

CreateDate() - create a date object CreateDate.cfm <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>CreateDate function example: how to create a date object</title> </head> <body> <h2 style="color:hotpink">CreateDate Function Example</h2> <cfset Year="1971"> <cfset Month="12"> <cfset Day="16"> <cfset CreatedDate=CreateDate(Year,Month,Day)> <cfoutput> <b> Year: #Year# <br /> Month: #Month# <br /> Day: #Day# <br /><br /> Created Date: #CreatedDate# <br /> Created Date: #DateFormat(CreatedDate)# </b> </cfoutput> </body> </html> More ColdFusion examples CreateDateTime() - create a date time object CreateODBCDateTime() - create an ODBC date time object CreateTimeSp...