Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

yyyymmddhhmm date format 1

Status
Not open for further replies.

rwei

Programmer
Nov 19, 2004
55
US
I need to find a way to convert the current date/time (i.e. Now()) into this "yyyymmddhhmm" format. Can anyone tell me how to do this? Can this be done?
 
Here's what I use:

Code:
currenttime = ConvWMIDateTime(objOS.LocalDateTime, "ISO8601")
Wscript.Echo "The time is " & currenttime

Function ConvWMIDateTime(sDMTFformat, iNamedFormat)

   Dim sYear, sMonth, sDay, sHour, sMinutes, sSeconds
   sYear = mid(sDMTFformat, 1, 4)
   sMonth = mid(sDMTFformat, 5, 2)
   sDay = mid(sDMTFformat, 7, 2)
   sHour = mid(sDMTFformat, 9, 2)
   sMinutes = mid(sDMTFformat, 11, 2)
   sSeconds = mid(sDMTFformat, 13, 2)

   ConvWMIDateTime = sYear & "-" & sMonth & "-" & sDay & " " _
                & sHour & ":" & sMinutes

   If IsNumeric(iNamedFormat) Then
     If iNamedFormat >= 0 And iNamedFormat <= 4 Then
       ' FormatDateTime will set date format to specified format
       ConvWMIDateTime = FormatDateTime(ConvWMIDateTime, iNamedFormat)
     End If
   End If
End Function
 
prob a ton of ways..but
Code:
response.write   year(date)&Month(date)&Day(date)&hour(time)&Minute(time)
 
myDateTime = Year(Date) & Right("0" & Month(Date), 2) & Right("0" & Day(Date), 2) _
& Right("0" & Hour(Now), 2) & Right("0" & Minute(Now), 2) & Right("0" & Second(Now), 2)

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Thank you all, I've tried with PHV's answer (with minor changes), and it works great!!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top