Re: SOLVED: This should be simple--why is it not working?
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 > > > > > 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")#; > > > > > Serial Value: #MyValue# > Date: #MyDate# (would output 06/14/01 and...) > Time: #MyTime# (would output 12:16 PM or the time you run this code) > > > > 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/cf-talk@houseoffusion.com/ Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists
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 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")#; Serial Value: #MyValue# Date: #MyDate# (would output 06/14/01 and...) Time: #MyTime# (would output 12:16 PM or the time you run this code) 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/cf-talk@houseoffusion.com/ Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists
SOLVED: This should be simple--why is it not working?
Okay, I'm a dork. Why do I always try to find the hard way to do things? I spent 2 hours trying to solve my problem. I tried using CreateDate, then DatePart to just get the year, DateFormat, etc. What I SHOULD have just done in the first place is used the "Right" function to just diplay the last two characters of the list_year variable. DOH! So, here's the modified select statement: selected>FY #right(list_year, 2)#/#right(end_fiscal, 2)# --- Hey all, I have a dropdown list that dynamically displays the fiscal years from 1999 up to the present fiscal year (so in this case, just 1999 and 2000. Once October ends, 2000 will be ended and 2001 will display in the picklist as well). Well, instead of the year being displayed in the list, they want the actual fiscal year to be displayed in the format of 99/00, 00/01, etc. But we would still pass the year as 1999, for example, for fiscal year 99/00. So the option VALUE would be 1999, but the DISPLAY would be FY 99/00. Okay, so that should be simple, right? I should just wrap the variable for display in a format mask like so: FY #dateformat(list_year, 'YY')#/#dateformat(IncrementValue(list_year), 'YY')# Before I even GOT to that point, I just tested it by wrapping list_year in a dateformat function like so: #dateformat(list_year, 'YY')#. BUT, this returns 05 for BOTH list items! Somehow CF sees the year as being 1905 when I wrap dateformat around it! Here is the code. Any ideas? selected>#list_year# ~~ Structure your ColdFusion code with Fusebox. Get the official book at http://www.fusionauthority.com/bkinfo.cfm Archives: http://www.mail-archive.com/cf-talk@houseoffusion.com/ Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists