I want the date to look like MM-DD-YYYY instead of MM/DD/YYYY.
The international standard recommends writing the date as year, then month, then the day: YYYY-MM-DD.
How-to: Get the current date [getdate. vbs] Return the current Year/Month/Day and Time formatted as a string. GetDate.
The IsDate function returns a Boolean value that indicates if the evaluated expression can be converted to a date. It returns True if the expression is a date or can be converted to a date; otherwise, it returns False.
0 = vbGeneralDate - Default. Returns date: mm/dd/yy and time if specified: hh:mm:ss PM/AM. 1 = vbLongDate - Returns date: weekday, monthname, year 2 = vbShortDate - Returns date: mm/dd/yy 3 = vbLongTime - Returns time: hh:mm:ss PM/AM 4 = vbShortTime - Return time: hh:mm d=CDate("2010-02-16 13:45") document.write(FormatDateTime(d) & "<br />") document.write(FormatDateTime(d,1) & "<br />") document.write(FormatDateTime(d,2) & "<br />") document.write(FormatDateTime(d,3) & "<br />") document.write(FormatDateTime(d,4) & "<br />")
If you want to use another format you will have to create your own function and parse Month, Year, Day, etc and put them together in your preferred format.
Function myDateFormat(myDate) d = TwoDigits(Day(myDate)) m = TwoDigits(Month(myDate)) y = Year(myDate) myDateFormat= m & "-" & d & "-" & y End Function Function TwoDigits(num) If(Len(num)=1) Then TwoDigits="0"&num Else TwoDigits=num End If End Function
edit: added function to format day and month as 0n
if value is less than 10
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With