Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for iso2date.vbs

(view source code of iso2date.vbs as plain text)

  1. Option Explicit
  2.  
  3. Dim blnDate, blnTime
  4. Dim intDateFormat, intTimeFormat, intValid
  5. Dim strResult
  6.  
  7. blnDate       = True
  8. blnTime       = True
  9. intDateFormat = vbShortDate
  10. intTimeFormat = vbShortTime
  11. intValid      = 0
  12. strResult     = ""
  13.  
  14. With WScript.Arguments.Named
  15. 	If .Exists( "D" ) Then
  16. 		If .Exists( "T" ) Then Syntax
  17. 		blnDate  = True
  18. 		blnTime  = False
  19. 		intValid = intValid + 1
  20. 	End If
  21. 	If .Exists( "T" ) Then
  22. 		blnDate  = False
  23. 		blnTime  = True
  24. 		intValid = intValid + 1
  25. 	End If
  26. 	If .Exists( "L" ) Then
  27. 		If .Exists( "S" ) Then Syntax
  28. 		intDateFormat = vbLongDate
  29. 		intTimeFormat = vbLongTime
  30. 		intValid      = intValid + 1
  31. 	End If
  32. 	If .Exists( "S" ) Then
  33. 		intDateFormat = vbShortDate
  34. 		intTimeFormat = vbShortTime
  35. 		intValid      = intValid + 1
  36. 	End If
  37. 	If intValid <> .Count Then Syntax
  38. End With
  39.  
  40. With WScript.Arguments.Unnamed
  41. 	If .Count < 1 Then Syntax
  42. 	If .Count > 2 Then Syntax
  43. 	' Specified date must be in yyyy-mm-dd format
  44. 	If UBound( Split( .Item(0), "-" ) ) <> 2 Then Syntax
  45. 	' Calculate and display the difference in seconds between the specified and the Unix time base date
  46. 	If blnDate Then strResult = FormatDateTime( CDate( .Item(0) ), intDateFormat )
  47. 	If blnTime Then
  48. 		If .Count = 2 Then
  49. 			' Specified date must be in yyyy-mm-dd format
  50. 			If UBound( Split( .Item(0), "-" ) ) <> 2 Then Syntax
  51. 			' Specified time must be in hh:mm or hh:mm:ss format
  52. 			If UBound( Split( .Item(1), ":" ) ) <  1 Then Syntax
  53. 			If UBound( Split( .Item(1), ":" ) ) >  2 Then Syntax
  54. 			' Calculate and display the difference in seconds between the specified and the Unix time base date
  55. 			If blnDate Then strResult = strResult & ", "
  56. 			strResult = strResult & FormatDateTime( CDate( .Item(1) ), intTimeFormat )
  57. 		Else
  58. 			Syntax
  59. 		End If
  60. 	End If
  61. 	WScript.Echo strResult
  62. End With
  63.  
  64.  
  65. Sub Syntax
  66. 	WScript.Echo vbCrLf _
  67. 	           & "ISO2Date.vbs,  Version 1.00" _
  68. 	           & vbCrLf _
  69. 	           & "Convert an ISO date/time to the current user's standard date/time format" _
  70. 	           & vbCrLf & vbCrLf _
  71. 	           & "Usage:  ISO2Date.vbs  iso_date  [ iso_time ]  [ /D | /T ]  [ /L | /S ]" _
  72. 	           & vbCrLf & vbCrLf _
  73. 	           & "Where:  ""iso_date""   is the mandatory ISO date to convert (YYYY-MM-DD format)" _
  74. 	           & vbCrLf _
  75. 	           & "        ""iso_time""   is the optional time component (HH:mm[:ss] format)" _
  76. 	           & vbCrLf _
  77. 	           & "        /D           Return the date only (default: both date and time)" _
  78. 	           & vbCrLf _
  79. 	           & "        /T           Return the time only (/D and /T are mutually exclusive)" _
  80. 	           & vbCrLf _
  81. 	           & "        /L           Use long format (/L and /S are mutually exclusive)" _
  82. 	           & vbCrLf _
  83. 	           & "        /S           Use short format (default)" _
  84. 	           & vbCrLf & vbCrLf _
  85. 	           & "Note:   When /T is used, iso_time becomes mandatory too." _
  86. 	           & vbCrLf & vbCrLf _
  87. 	           & "Written by Rob van der Woude" _
  88. 	           & vbCrLf _
  89. 	           & "http://www.robvanderwoude.com"
  90. 	WScript.Quit 1
  91. End Sub
  92.  

page last modified: 2024-04-16; loaded in 0.0094 seconds