Very cool, thanks for the explanation.

jon
----- Original Message -----
From: "Steve Reich" <[EMAIL PROTECTED]>
To: "CF-Talk" <[EMAIL PROTECTED]>
Sent: Thursday, June 14, 2001 1:02 PM
Subject: Re: SOLVED: This should be simple--why is it not working?


> > Somehow CF sees the year as being 1905 when
> > I wrap dateformat around it [#dateformat("2001", 'YY')#]!
>
> CF was correct! 2001 is the numeric value of the date 06/23/1905. Here's a
> quick lesson on numeric date (and time) values....
>
> DateFormat("6/14/2001", "YY") would output 01
>
> DateFormat("2001", "YY") would view 2001 as the numeric value of a date
> which would be 2001 days past Dec 30, 1899 or 06/23/1905, hence your
> returned year value of 1905.
>
> If you do a number format on a date such as NumberFormat("6/14/2001") you
> would get 37,056 returned as the value (37,056 days past Dec. 30, 1899).
The
> same is true for the time which is returned in a decimal format.
>
> So if you did NumberFormat(Now(), "_____.__________") you would get
> 37056.5117245370. This value equals {ts '2001-06-14 12:16:53'} as a date.
>
> Then to convert these back starting with 37056.5117245370...
>
> #DateFormat("37056", "mm/dd/yy)# to get 06/14/01 and....
> #TimeFormat(".5117245370", "h:mm tt")# to get 12:16 PM
>
> You can also do it with the complete value...
>
> #DateFormat("37056.5117245370", "mm/dd/yy)# to get 06/14/01 and....
> #TimeFormat("37056.5117245370", "h:mm tt")# to get 12:16 PM
>
> or for code to run in your browser....
>
> <!---------SNIP---------->
> <cfscript>
>
>     MyValue = #NumberFormat(Now(), "_____.__________")#;
>     MyDate = #DateFormat(ListFirst(MyValue, "."), "mm/dd/yy")#;
>
> /* Be sure to add the decimal back in the first parameter of the
> TimeFormat() function */
>
>     MyTime = #TimeFormat("." & ListLast(MyValue, "."), "h:mm tt")#;
>
> </cfscript>
>
> <cfoutput>
> Serial Value: #MyValue#<br>
> Date: #MyDate# (would output 06/14/01 and...)<br>
> Time: #MyTime# (would output 12:16 PM or the time you run this code)
> </cfoutput>
> <!---------SNIP---------->
>
> Try it! It really does work quite well. This is an old approach that I
think
> was originally developed in spreadsheet applications. I have used this
> method with a calendar applications and it's an interesting approach to
> dealing with dates. It can get confusing, but it is extremely accurate and
> effective in calculating date differences once you get the hang of it.
> Better than DateAdd? This is yet to be debated, but at least you have a
> little more understanding of what was originally happening with your code.
>
> HTH,
> Steve
>
>
>
>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Structure your ColdFusion code with Fusebox. Get the official book at 
http://www.fusionauthority.com/bkinfo.cfm

Archives: http://www.mail-archive.com/[email protected]/
Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists

Reply via email to