home *** CD-ROM | disk | FTP | other *** search
/ Chip 2002 February / CHIPCD_02_2002.iso / Internet / Macromedia ColdFusion Server 5 / coldfusion-50-win-us.exe / data1.cab / Examples / CFDOCS / snippets / dateconvert.cfm < prev    next >
Encoding:
Text File  |  2001-06-13  |  2.7 KB  |  80 lines

  1. <HTML>
  2.  
  3. <HEAD>
  4. <TITLE>
  5. DateConvert Example
  6. </TITLE>
  7. </HEAD>
  8.  
  9. <BASEFONT FACE="Arial, Helvetica" SIZE=2>
  10.  
  11. <BODY  bgcolor="#FFFFD5">
  12.  
  13. <H3>DateConvert Example</H3>
  14. <!--- This example shows the use of DateConvert --->
  15.  
  16. <!--- This part of the example shows the conversion of the current date and time to UTC time and back again. --->
  17.  
  18. <CFSET curDate = Now()>
  19. <P><CFOUTPUT>The current date and time: #curDate#. </CFOUTPUT></P>
  20. <CFSET utcDate = DateConvert("local2utc", curDate)>
  21. <CFOUTPUT>
  22.     <P>The current date and time converted to UTC time: #utcDate#.</P> 
  23. </CFOUTPUT> 
  24.  
  25. <!--- This code checks to see if the form was submitted. 
  26.       If it was submitted the code generates the CFML date with the CreateDateTime function. --->    
  27.  
  28. <CFIF IsDefined("form.submit")>
  29.     <CFSET yourDate = CreateDateTime(form.year, form.month, form.day, form.hour, form.minute, form.second)>
  30.     <p><CFOUTPUT>Your date value, presented as a ColdFusion date-time string:#yourdate#.</CFOUTPUT></p>
  31.     <CFSET yourUTC = DateConvert("local2utc", yourDate)>
  32.     <P><CFOUTPUT>Your date and time value, converted into Universal Coordinated Time (UTC): #yourUTC#.</CFOUTPUT></P>
  33.     <P><CFOUTPUT>Your UTC date and time, converted back to local date and time: #DateConvert("utc2local", yourUTC)#.</CFOUTPUT></P>
  34. <CFELSE>
  35.     Type the date and time, and press Enter to see the conversion.
  36. </CFIF>    
  37.     
  38.  
  39. <HR size="2" color="#0000A0">
  40.  
  41. <FORM ACTION="dateconvert.cfm" METHOD="POST">
  42. <P>Please enter the year, month and day in integer format for 
  43. the date value you would like to view:
  44.  
  45.  
  46. <table cellspacing="2" cellpadding="2" border="0">
  47. <tr>
  48.     <td>Year</td>
  49.     <td><INPUT TYPE="Text" NAME="year" VALUE="1998" VALIDATE="integer" REQUIRED="Yes"></td>
  50. </tr>
  51. <tr>
  52.     <td>Month</td>
  53.     <td><INPUT TYPE="Text" NAME="month" VALUE="6" RANGE="1,12" MESSAGE="Please enter a month (1-12)" VALIDATE="integer" REQUIRED="Yes"></td>
  54. </tr>
  55. <tr>
  56.     <td>Day</td>
  57.     <td><INPUT TYPE="Text" NAME="day" VALUE="8" RANGE="1,31" MESSAGE="Please enter a day of the month (1-31)" VALIDATE="integer" REQUIRED="Yes"></td>
  58. </tr>
  59. <tr>
  60.     <td>Hour</td>
  61.     <td><INPUT TYPE="Text" NAME="hour" VALUE="16" RANGE="0,23" MESSAGE="You must enter an hour (0-23)" VALIDATE="integer" REQUIRED="Yes"></td>
  62. </tr>
  63. <tr>
  64.     <td>Minute</td>
  65.     <td><INPUT TYPE="Text" NAME="minute" VALUE="12" RANGE="0,59" MESSAGE="You must enter a minute value (0-59)" VALIDATE="integer" REQUIRED="Yes"></td>
  66. </tr>
  67. <tr>
  68.     <td>Second</td>
  69.     <td><INPUT TYPE="Text" NAME="second" VALUE="0" RANGE="0,59" MESSAGE="You must enter a value for seconds (0-59)" VALIDATE="integer" REQUIRED="Yes"></td>
  70. </tr>
  71. <tr>
  72.     <td><INPUT TYPE="Submit" NAME="submit" VALUE="Submit"></td>
  73.     <td><INPUT TYPE="RESET"></td>
  74. </tr>
  75. </table>
  76.  
  77. </BODY>
  78. </HTML>
  79.  
  80.