CFLib.org – Common Function Library Project

DifferentMonth(date1, date2)

Last updated March 21, 2002

Version: 1 | Requires: ColdFusion 5 | Library: DateLib

 
Rated 0 time(s). Average Rating: 0

Description:
Check if two dates refer to the same month. This is different from using the built-in function DateDiff("m") as it will only count whole months difference, whereas a difference of just a second could be the difference between one month and another.

Return Values:
Returns a boolean.

Example:

view plain print about
<cfoutput>
DifferentMonth test:
#DifferentMonth("{ts '2002-12-31 23:59:59'}","{ts '2003-01-01 00:00:00'}")#<br>
Compare to DateDiff: 
#DateDiff("m","{ts '2002-12-31 23:59:59'}","{ts '2003-01-01 00:00:00'}")#<br>
</cfoutput>

Parameters:

Name Description Required
date1 First date to check. Yes
date2 Second date to check. Yes

Full UDF Source:

view plain print about
<cfscript>
/**
 * Check if two dates refer to the same month.
 * 
 * @param date1      First date to check. 
 * @param date2      Second date to check. 
 * @return Returns a boolean. 
 * @author Matthew Walker (matthew@cabbagetree.co.nz) 
 * @version 1, March 21, 2002 
 */

function DifferentMonth(date1, date2) {
    return ( ( Month(date1) NEQ Month(date2) ) OR ( Year(date1) NEQ Year(date2) ) );
}
</cfscript>
blog comments powered by Disqus

Search CFLib.org


Latest Additions

Dave Anderson Dave Anderson added
iniToStruct
20 day(s) ago

Dave Anderson Dave Anderson added
deDupeArray
20 day(s) ago

Richard Richard added
dice
22 day(s) ago

Isaac Dealey Isaac Dealey added
getRelative
a while ago

Top Rated

Darwan Leonardo Sitepu backupDatabase
Rated 5.0, 22 time(s)

Barney Boisvert indentXml
Rated 5.0, 10 time(s)

Kevin Pepperman generateSsccAsn
Rated 5.0, 4 time(s)

Raymond Camden highlightAndCrop
Rated 5.0, 4 time(s)

Created by Raymond Camden / Design by Justin Johnson