QualitativeDate(date)
Last updated April 15, 2002
Version: 1 | Requires: CF5 | Library: DateLib
Description:
Returns a qualitative description of a date, such as "Yesterday" or "Later this month".
Return Values:
Returns a string.
Example:
<cfset StartDate=Now()-10>
<cfset EndDate=Now()+10>
<cfloop from="#StartDate#" to="#EndDate#" index="TheDate">
<cfoutput>
#LSDateFormat(TheDate)#: #QualitativeDate(TheDate)#<br>
</cfoutput>
</cfloop>
Parameters:
Name | Description | Required |
---|---|---|
date | Date you want to return a qualitative description for. | Yes |
Full UDF Source:
/**
* Qualitative description of a date.
*
* @param date Date you want to return a qualitative description for.
* @return Returns a string.
* @author Matthew Walker (matthew@cabbagetree.co.nz)
* @version 1, April 15, 2002
*/
function QualitativeDate(Date) {
var Today = Now();
var YearsDifference = Year(Today) - Year(Date);
var MonthsDifference = Month(Today) - Month(Date);
var WeeksDifference = Week(Today) - Week(Date);
var DaysDifference = DayOfWeek(Today) - DayOfWeek(Date);
if ( DateCompare(Date, Now()) LT 1 ) {
if ( YearsDifference GT 2 )
return "A long time ago";
if ( YearsDifference EQ 2 )
return "Two years ago";
if ( YearsDifference EQ 1 )
return "Last year";
if ( MonthsDifference GT 2 )
return "Earlier this year";
if ( MonthsDifference EQ 2 )
return "Two months ago";
if ( MonthsDifference EQ 1 )
return "Last month";
if ( WeeksDifference GT 2 )
return "Earlier this month";
if ( WeeksDifference EQ 2 )
return "Two weeks ago";
if ( WeeksDifference EQ 1 )
return "Last week";
if ( DaysDifference GT 1 )
return "Earlier this week";
if ( DaysDifference EQ 1 )
return "Yesterday";
return "Today";
}
else {
if ( YearsDifference LT -1 )
return "Sometime in the future";
if ( YearsDifference EQ -1 )
return "Next year";
if ( MonthsDifference LT -1 )
return "Later this year";
if ( MonthsDifference EQ -1 )
return "Next month";
if ( WeeksDifference LT 0 )
return "Later this month";
if ( DaysDifference LT -2 )
return "Later this week";
if ( DaysDifference EQ -2 )
return "Two days from now";
if ( DaysDifference EQ -1 )
return "Tomorrow";
return "Today";
}
}
Search CFLib.org
Latest Additions
Raymond Camden added
QueryDeleteRows
November 04, 2017
Leigh added
nullPad
May 11, 2016
Raymond Camden added
stripHTML
May 10, 2016
Kevin Cotton added
date2ExcelDate
May 05, 2016
Raymond Camden added
CapFirst
April 25, 2016