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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Date Time Formating Help

Status
Not open for further replies.

twooly

MIS
Feb 22, 2004
122
US
I'm having a terrible time trying to format date/time from the installed software registry key (uninstall key) due to many formats being used.

Some example dates:
Code:
Fri Nov 02 19:20:55 CST 2007
9/18/2006
4-26-2004

Does anyone have ideas on how I can best do this? I need to format to a mysql date time field and I can format the last 2 examples, its the first one that is throwing me off.

Here is what I have so far
Code:
Function mySqlDate(myDate)
	If Len(myDate) > 0 Then
		If Len(myDate) > 8 Then
			YMD = ( Year(myDate)*100 + Month(myDate) )*100 + Day(myDate)
			hms = Right((Hour(myDate)*100+Minute(myDate))*100+Second(myDate)+1e7, 6)
			mySqlDate = Left(YMD,4) & "-" & Mid(YMD,5,2) & "-" & Mid(YMD,7,2) & " " & Left(hms,2) & ":" & Mid(hms,3,2) & ":" & Mid(hms,5,2)
		Else
			mySQLDate = Left(myDate,4) & "-" & Mid(myDate,5,2) & "-" & Mid(myDate,7,2)
		End If
	Else
		mySqlDate = "0000-00-00"
	End If
End Function

Thanks
 
If you only want the date and not the time, then here is a simpler solution.

Code:
dString = "Fri Nov 02 19:20:55 CST 2007"
dArray = Split(dString," ")
thisDate = CDate(dArray(1) & " " & dArray(2) & " " & dArray(5))
WScript.Echo thisDate

I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
Work SMARTER not HARDER. The Spider's Parlor's Admin Script Pack is a collection of Administrative scripts designed to make IT Administration easier! Save time, get more work done, get the Admin Script Pack.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top