DaniWeb IT Discussion Community

Code Snippets (http://www.daniweb.com/code/)
-   asp (http://www.daniweb.com/code/asp.html)
-   -   Time Formatting (http://www.daniweb.com/code/snippet46.html)

Drew asp syntax
Sep 20th, 2004
Learn how to take the Now() command and format it in a bunch of differnt ways.

Code from: http://www.iportalx.net

  1. <%= Date() %>
  2. Produces: 07/01/2002
  3.  
  4. <%= Now() %>
  5. Produces: 07/01/2002 3:47:42 PM
  6.  
  7. <%= Time() %>
  8. Produces: 3:47:42 PM
  9.  
  10. <%= FormatDateTime(strDate, 0) %>
  11. Produces: 07/01/2002 3:47:42 PM
  12.  
  13. <%= FormatDateTime(strDate, 1) %>
  14. Produces: Monday, July 01, 2002
  15.  
  16. <%= FormatDateTime(strDate, 2) %>
  17. Produces: 07/01/2002
  18.  
  19. <%= FormatDateTime(strDate, 3) %>
  20. Produces: 3:47:42 PM
  21.  
  22. <%= FormatDateTime(strDate, 4) %>
  23. Produces: 15:47
  24.  
  25. <%= Year(strDate) %>
  26. Produces: 2002
  27.  
  28. <%= Month(strDate) %>
  29. Produces: 7
  30.  
  31. <%= MonthName(Month(strDate)) %>
  32. Produces: July
  33.  
  34. <%= MonthName(Month(strDate), 1) %>
  35. Produces: Jul
  36.  
  37. <%= Day(strDate) %>
  38. Produces: 1
  39.  
  40. <%= WeekDay(strDate) %>
  41. Produces: 2
  42.  
  43. <%= WeekDayName(WeekDay(strDate)) %>
  44. Produces: Monday
  45.  
  46. <%= WeekDayName(WeekDay(strDate), 1) %>
  47. Produces: Mon
  48.  
  49. <%= Minute(strDate) %>
  50. Produces: 47
  51.  
  52. <%= Second(strDate) %>
  53. Produces: 42
  54.  
  55. <%= DateAdd("d", 1, strDate) %>
  56. Produces: 07/02/2002 3:47:42 PM
  57.  
  58. <%= DateAdd("d", -1, strDate) %>
  59. Produces: 06/30/2002 3:47:42 PM
  60.  
  61. <%= DateDiff("d", "1/1/2000", strDate) %>
  62. Produces: 912
  63.  
  64. <%= Day(strDate) & "/" & Month(strDate) & "/" & Year(strDate) %>
  65. Produces: 1/7/2002
  66.  
  67. <%= WeekDayName(WeekDay(strDate)) & ", " & Day(strDate) & " " & MonthName(Month(strDate)) & ", " & Year(strDate) %>
  68. Produces: Monday, 1 July, 2002