vbscript - VBS objFile.DateLastModified and Date Format Settings -
i'm trying date modify check file in vbs script. looks comparison operation depend on date format set on machine script runnnig. have diverse machines regioanal & date settings russian, english us, english uk , need run vbs against machines , being able compare date correctly.
when i'm trying use
if objfile.datelastmodified = cdate("19.10.2012 11:34:06") else else end if
it seemingly works , doing correct comparison on machine russian formats setting, fails on machine english uk formats setting following error
type mismatch: 'cdate' 800a000d
if use following dateserial(2012,10,19)
doesn't throw error fail compare dates correctly.
what best , easiest way compare file modify date against predifined value vbs irrespectively of machine date format setting?
long story short: don't use localized date formats when parsing dates.
iso 8601 format works fine:
if objfile.datelastmodified = cdate("2012-10-19 11:34:06") ' else ' else end if
if must, can use setlocale()
function explicitly make script run under different environments:
setlocale 1049 ' lcid "russian" msgbox cdate("5.4.2013 15:00:00") ' april 5, shown 05.04.2013 15:00:00 setlocale 1033 ' lcid "english - united states" msgbox cdate("5.4.2013 15:00:00") ' type mismatch error
refer list of assigned lcids on msdn.
Comments
Post a Comment