Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.
;******************************************************************************************* ;Multiple Date Converter ; original program by DaveG ; additions & enhancements by Rick Hawley, Jr. ; Converts just about any date format to any other date format. ; Written under WinBatch ver. 2003F. ;******************************************************************************************* ;QUICK SYNTAX: ;dc(date,outtype) ;ddiff(date1,date2) (order is not important) ;daft(date,ndays,outtype) ;dbef(date,ndays,outtype) ; date (possible incoming date formats, see many more choices below): ; "" (udf uses current date) ; YYYY:MM:DD[:HH:MM:SS] (YmdHms; time, if present, is ignored) ; DWD M/D/YYYY [H:M:S P] (TimeDate; time, if present, is ignored) ; J (Julian) ; MWD D, YYYY (full month txt or 3-ltr abbreviation) ; M/D/[YY]YY (or zero-padded, or with hyphens, YY presumes current century) ; outtype (string values to produce indicated output format, see many morechoices below): ; ymdhms [time will always be 00:00:00] ; julian ; timedate [time will always be 00:00:00 AM] ; slash 6/3/2003 ; paddedslash 06/03/2003 ; dayregular Friday, June 13, 2003 ; regular June 13, 2003 ;******************************************************************************************* ;COMPLETE SYNTAX: ;dc(date,outtype) ;parameters: ; date - ; The acceptable input formats are: ; "" (uses current time) ; YYYY:MM:DD[:HH:MM:SS] (YmdHms; time, if present, is ignored) ; DWD M/D/YYYY [H:M:S P] (TimeDate; time, if present, is ignored) ; J (Julian) ; MWD D, YYYY ; DWD, MWD D, YYYY ; M/D/YY ; M/D/YYYY ; M-D-YY ; M-D-YYYY ; D-MWD-YYYY ; D-MWD-YY ; D/MWD/YYYY ; D/MWD/YY ; YYYYMMDD (this is YmdHms format, with colons removed) ; YYYY/MM/DD (YYYY must be 4 digits to use this one) ; YYYY/MWD/DD (YYYY must be 4 digits to use this one) ; MWD is Month in words, case and trailing or leading spaces are unimportant, ; but the string must otherwise be exactly one of the following): ; JAN FEB MAR APR MAY JUN JUL AUG SEP OCT NOV DEC JANUARY ; FEBRUARY MARCH APRIL MAY JUNE JULY AUGUST SEPTEMBER OCTOBER NOVEMBER DECEMBER ; DWD is Day in words, can be full or abbreviated (is ignored, makes little difference). ; Numerical months and days can be with or without zero padding in all formats. ; Years must either be one or two digits, as indicated above. If only two digits ; are given, the year is presumed to have the same two first digits as the current year. ; outtype ; an integer number or string (case-insensitive) as follows: ; value output ; 1 or "ymdhms" 2003:06:13:00:00:00 [time will always be 00:00:00] ; 2 or "julian" 731745 ; 3 or "slash" 6/3/2003 ; 4 or "paddedslash" 06/03/2003 ; 5 6/13/03 ; 6 06/13/03 ; 7 or "dayregular Friday, June 13, 2003 ; 8 13-Jun-2003 ; 9 13-June-2003 ; 10 13-Jun-2003 ; 11 13-June-2003 ; 12 13 Jun 2003 ; 13 13 June 2003 ; 14 Friday, the 13th day of June, 2003 ; 15 or "timedate" Fri 6/13/2003 00:00:00 AM [time will always be 00:00:00 AM] ; 16 13Jun03 ; 17 20030613000000 [time will always be 000000] ; 18 or "regular" June 13, 2003 ; 19 yyyymmdd (added 11/20/03 - Rick Hawley, Jr.) ;******************************************************************************************* ;******************************************************************************************* #definefunction dc(date,outtype) if date == "" then date = timeymdhms() d = strtrim(date) d = strreplace(d,"."," ") d = strreplace(d,"-","/") d = strReplace(d,"\","/") while StrIndex (d," ",0,@fwdscan) <> 0 ;convert double spaces to single spaces d = strreplace(d," "," ") endwhile ;find first two delimiters type = "" p = -1 for iter = 1 to 2 p = StrScan(d,": ,/",p+1,@fwdscan) if p == 0 ;if there are no delimiters in the date if isNumber(d) && strLen(d) == 8 then dlim = 48 else dlim = 0 ;its a julian date if it's an integer less than 8 characters long if !isNumber(d) then dlim = 999 ;it's a bad input type if it's not a number else dlim = Char2Num(strsub(d,p,1)) endif type = strcat(type,dlim) next type = int(type) ;FYI- 58= ":" 32= " " 44= "," 47= "/" 48= "0" 999="BAD TYPE" switch type case 0 ;julian d = timeJulToYmd(d) ;break intentionally omitted case 5858 ;YYYY:MM:DD:HH:MM:SS d = strreplace(d,":"," ") mo = itemextract(2,d," ") day = itemextract(3,d," ") year = itemextract(1,d," ") break case 4432 ;DWD, MWD D, YYYY d = itemremove(1,d," ") ;break intentionally omitted case 3244 ;MWD D, YYYY d = strreplace(d,",","") mo = itemextract(1,d," ") day = itemextract(2,d," ") year = itemextract(3,d," ") break case 3247 ;DWD M/D/YYYY H:M:S P d = itemextract(2,d," ") d = strreplace(d,"/"," ") mo = itemextract(1,d," ") day = itemextract(2,d," ") year = itemextract(3,d," ") break case 4747 ;x/x/x (must subtype) d = strreplace(d,"/"," ") if isNumber(itemExtract(1,d," ")) && strLen(itemExtract(1,d," ")) == 4 && isNumber(itemExtract(3,d," ")) mo = itemExtract(2,d," ") day = itemExtract(3,d," ") year = itemExtract(1,d," ") break endIf if IsNumber(itemextract(2,d," ")) mo = itemextract(1,d," ") day = itemextract(2,d," ") year = itemextract(3,d," ") else mo = itemextract(2,d," ") day = itemextract(1,d," ") year = itemextract(3,d," ") endif break case 4848 ;yyyymmdd format, (eg. 20031203) -- (added 12/3/2003, Rick Hawley, Jr.) mo = strSub(d,5,2) day = strSub(d,7,2) year = strSub(d,1,4) break case type ;message("Error","Input date format is unacceptable. Aborting") ;exit d = "BAD TYPE" break endswitch if d == "BAD TYPE" then return 0 ;convert month moStr1="Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec" moStr2="January February March April May June July August September October November December" if isnumber(mo) == @false mwdr = strupper(mo) mo = 0 mo = ItemLocate(mwdr,strupper(moStr1)," ") if mo == 0 ;it must be in the long list mo = ItemLocate(mwdr,strupper(moStr2)," ") mwdl = itemextract(mo,moStr2," ") ;why not just mwdl = mwdr? ; To get first-letter-uppercase format mwds = itemextract(mo,moStr1," ") else ;it's in the short list mwdl = itemextract(mo,moStr2," ") mwds = itemextract(mo,moStr1," ") endif else intControl(73,2,0,0,0) mo = int(mo) if mo == 0 then return 0 mwds = itemextract(mo,moStr1," ") mwdl = itemextract(mo,moStr2," ") endif ;pad numeric month mop = StrFixLeft(mo,"0",2) ;process day intControl(73,2,0,0,0) day = int(day) if day == 0 then return 0 dayp = StrFixLeft(day,"0",2) ;convert year intControl(73,2,0,0,0) year = int(year) if year == 0 then return 0 if strlen(year) < 4 year = StrFixLeft(year,"0",2) decade = strsub(timeymdhms(),1,2) year = strcat(decade,year) endif ;build ymdhms style date ymdhms = strcat(year,":",mop,":",dayp,":00:00:00") ;get julian date julian = TimeJulianDay(ymdhms) ;get day of week daysofweek = "Sunday Monday Tuesday Wednesday Thursday Friday Saturday" dwdl = ItemExtract(((julian+5) mod 7) + 1, daysofweek, " ") dwds = strsub(dwdl,1,3) ;make output format ;convert words outtype = strtrim(outtype) if !isnumber(outtype) outtype = strlower(outtype) if outtype == "ymdhms" then outtype = 1 if outtype == "julian" then outtype = 2 if outtype == "slash" then outtype = 3 if outtype == "paddedslash" then outtype = 4 if outtype == "dayregular" then outtype = 7 if outtype == "timedate" then outtype = 15 if outtype == "regular" then outtype = 18 endif switch outtype case 1 ;ymdhms retval = ymdhms break case 2 ;julian retval = julian break case 3 ;human short 3/4/2005 retval = strcat(mo,"/",day,"/",year) break case 4 ;human short padded 03/04/2005 retval = strcat(mop,"/",dayp,"/",year) break case 5 ;human very short 3/4/05 retval = strcat(mo,"/",day,"/",strsub(year,3,2)) break case 6 ;human very short padded 03/04/05 retval = strcat(mop,"/",dayp,"/",strsub(year,3,2)) break case 7 ;human long Friday, March 4, 2005 retval = strcat(dwdl,", ",mwdl," ",day,", ",year) break case 8 ;human international short 4-Mar-2005 retval = strcat(day,"-",mwds,"-",year) break case 9 ;human international long 4-March-2005 retval = strcat(day,"-",mwdl,"-",year) break case 10 ;human international short padded 04-Mar-2005 retval = strcat(dayp,"-",mwds,"-",year) break case 11 ;human international long padded 04-March-2005 retval = strcat(dayp,"-",mwdl,"-",year) break case 12 ;human international short sps 4 Mar 2005 retval = strcat(day," ",mwds," ",year) break case 13 ;human international long sps 4 March 2005 retval = strcat(day," ",mwdl," ",year) break case 14 ;th form Friday, the 4th day of March, 2005 len = strlen(day) sigdigit = strsub(day,len,1) if sigdigit == 1 then tht = "st" if sigdigit == 2 then tht = "nd" if sigdigit == 3 then tht = "rd" if sigdigit >= 4 || sigdigit == 0 then tht = "th" retval = strcat(dwdl,", the ",day,tht," day of ",mwdl,", ",year) break case 15 ;TimeDate Fri 3/4/2005 00:00:00 AM retval = strcat(dwds," ",mo,"/",day,"/",year," 00:00:00 AM") break case 16 ;Airline chunklet 04Mar05 retval = strcat(dayp,mwds,strsub(year,3,2)) break case 17 ;YmdHms collapsed 20050304000000 retval = strreplace(YmdHms,":","") break case 18 ;human long (no day of week) March 4, 2005 retval = StrCat(mwdl," ",day,", ",year) Break case 19 ;yyyymmdd 20050304 retval = strSub(strreplace(YmdHms,":",""),1,8) break endswitch return retval ;----- :WBERRORHANDLER ;this just automatically returns to where we're using the intControl(73,2,0,0,0) return ;***** #endfunction #definefunction ddiff(date1,date2) ;calculates number of days between them, order doesn't matter retval = abs(dc(date1,2) - dc(date2,2)) return retval #endfunction #definefunction daft(date,ndays,outtype) ;what's the date ndays after date? retval = dc(dc(date,2) + ndays,outtype) return retval #endfunction #definefunction dbef(date,ndays,outtype) ;what's the date ndays before date? retval = dc(dc(date,2) - ndays,outtype) return retval #endfunction ;******************************************************************************************* ;******************************************************************************************* ;demos ; ;c = "" ;for i = 1 to 17 ; c = strcat(c,dc("",i),@crlf) ;next ;message("Your current date is",c) ; ;date1 = "July 21, 2003" ;date2 = "July 14, 2003" ;c = ddiff(date1,date2) ;message("ddif example","There are %c% days between %date1% and %date2%.") ; ;d = daft(date2,7,14) ;e = dbef(date2,7,14) ;message("daft/dbef example","7 days before %date2% is %e% and%@crlf%7 days after %date2% is %d%.") ;f = dc(date,19) ;message("yyyymmdd example",f)
Article ID: W16256
File Created: 2005:01:14:11:13:40
Last Updated: 2005:01:14:11:13:40