简体   繁体   中英

Vbscript How to find what is give date format?

I want to know what is the format of given date in vbscript? Example

If the date is 10/08/2015 I want to check whether which format it its?

dd/mm/yyyy or dd/mm/yy

I check so many function is vbs nothing fit for my requirement

The following function might be useful in some situations. It can distinguish between dd/mm/yyyy and mm/dd/yyyy when possible and tells you when not. It does no error checking so would give misleading results if the string is anything other than a valid date in one of those two formats:

Function FormatUsed(dateString)
    Dim parts, first, second

    parts = Split(dateString, "/")
    first = CInt(parts(0))
    second = CInt(parts(1))

    If first > 12 Then
        FormatUsed = "dd/mm/yyyy"
    ElseIf second > 12 Then
        FormatUsed = "mm/dd/yyyy"
    Else
        FormatUsed = "??/??/yyyy"
    End If
End Function

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM