Search code examples
vbscriptasp-classic

Classic ASP / VBSCRIPT 12 Hour Format from FormatDateTime()


I sure would appreciate some help. I was able to hack away at getting my time formatted as 8:53 AM from a value such as this 7/31/2020 08:53:20 AM with the following.

replace(replace(formatdatetime(formatdatetime(myRS("dateTime"),4)),":00 AM"," AM"),":00 PM"," PM")

But I would think there is a more efficient approach no?


Solution

  • Set speech = CreateObject("sapi.spvoice")
    Speech.speak "Here's one way it sets the locale to New Zealand which is 12 hours  - it does NOT set time zone"
    SetLocale("en-nz")
    speech.speak now()
    speech.speak "Here's another way" 'if locale is 12 hours it does nothing
    Do
        If Hour(Now) < 12 then 
            Var = Hour(Now) & " AM"
        else
            Var = Hour(Now) - 12 & " PM" 
        End If
    
        speech.Speak Var &  " and " & Minute(Now) & " minutes and " & Second(Now) & " seconds"
        wscript.sleep 5
    Loop
    

    As you can see it speaks the comments.