How can I loop over the days in a month and do something with each day?
As I have covered before in my blog, looping over dates in ColdFusion is super easy! The beauty of it is that you can treat dates like they are numbers and numbers like they are dates (if it is the right circumstances). All we have to do in this case is start at the first day of the month and loop to the last day in the month:
Launch code in new window » Download code as text file »
Notice in the above loop that I am loop to the last day in the current month (subtracting one from the start of the next month). We have to do this because the CFLoop index loop is an INCLUSIVE loop. That means it includes both the start and end indexes of the loop range.
The above example give us:
Oct 1, 2006
Numeric Value: 38991
IsNumericDate(): YES
IsDate(): NO
Oct 2, 2006
Numeric Value: 38992
IsNumericDate(): YES
IsDate(): NO
Oct 3, 2006
Numeric Value: 38993
IsNumericDate(): YES
IsDate(): NO
Oct 4, 2006
Numeric Value: 38994
IsNumericDate(): YES
IsDate(): NO
Oct 5, 2006
Numeric Value: 38995
IsNumericDate(): YES
IsDate(): NO
Oct 6, 2006
Numeric Value: 38996
IsNumericDate(): YES
IsDate(): NO
Oct 7, 2006
Numeric Value: 38997
IsNumericDate(): YES
IsDate(): NO
Oct 8, 2006
Numeric Value: 38998
IsNumericDate(): YES
IsDate(): NO
Oct 9, 2006
Numeric Value: 38999
IsNumericDate(): YES
IsDate(): NO
Oct 10, 2006
Numeric Value: 39000
IsNumericDate(): YES
IsDate(): NO
Oct 11, 2006
Numeric Value: 39001
IsNumericDate(): YES
IsDate(): NO
Oct 12, 2006
Numeric Value: 39002
IsNumericDate(): YES
IsDate(): NO
Oct 13, 2006
Numeric Value: 39003
IsNumericDate(): YES
IsDate(): NO
Oct 14, 2006
Numeric Value: 39004
IsNumericDate(): YES
IsDate(): NO
Oct 15, 2006
Numeric Value: 39005
IsNumericDate(): YES
IsDate(): NO
Oct 16, 2006
Numeric Value: 39006
IsNumericDate(): YES
IsDate(): NO
Oct 17, 2006
Numeric Value: 39007
IsNumericDate(): YES
IsDate(): NO
Oct 18, 2006
Numeric Value: 39008
IsNumericDate(): YES
IsDate(): NO
Oct 19, 2006
Numeric Value: 39009
IsNumericDate(): YES
IsDate(): NO
Oct 20, 2006
Numeric Value: 39010
IsNumericDate(): YES
IsDate(): NO
Oct 21, 2006
Numeric Value: 39011
IsNumericDate(): YES
IsDate(): NO
Oct 22, 2006
Numeric Value: 39012
IsNumericDate(): YES
IsDate(): NO
Oct 23, 2006
Numeric Value: 39013
IsNumericDate(): YES
IsDate(): NO
Oct 24, 2006
Numeric Value: 39014
IsNumericDate(): YES
IsDate(): NO
Oct 25, 2006
Numeric Value: 39015
IsNumericDate(): YES
IsDate(): NO
Oct 26, 2006
Numeric Value: 39016
IsNumericDate(): YES
IsDate(): NO
Oct 27, 2006
Numeric Value: 39017
IsNumericDate(): YES
IsDate(): NO
Oct 28, 2006
Numeric Value: 39018
IsNumericDate(): YES
IsDate(): NO
Oct 29, 2006
Numeric Value: 39019
IsNumericDate(): YES
IsDate(): NO
Oct 30, 2006
Numeric Value: 39020
IsNumericDate(): YES
IsDate(): NO
Oct 31, 2006
Numeric Value: 39021
IsNumericDate(): YES
IsDate(): NO
Download Code Snippet ZIP File
Comments (0) | Post Comment | Ask Ben | Permalink | Other Searches | Print Page
There are no comments posted for this web log entry.