English Translation of Script Examples vbscript autoit php batch
Sprache ändernEnglish (United Kingdom) German (DE)

vbscript Date Time Functions - Syntax Reference

(6)
rate this article
(67)

using and converting date and time values vbscript

some Shortcuts you should know before beginning:
DateInterval:
yyyy for Year
q for Quarter
m for Month
y for Year
d for Day
w for Weekday
h for hour
n for Minute
s for second

but lets start with the functions:

now
returns the actual date and time
Example: wscript.echo now
Output: 10.12.2008 20:36:54 (tt.mm.yyyy hh:mm:ss)

date
the function date displays the actual date
Example: wscript.echo date
Output: 10.12.2008 (tt.mm.yyyy)

time
the function time displays the actual time
Example: wscript.echo time
Output: 20:26:08 (hh.mm.ss)

CDate
converts a date and time variable into the standard date and time format:
Example:
d="12,10,2008"
wscript.echo cdate(d)

Output:10.12.2008

isdate
used to test if a variable has a valid date format
Example:
d="12.10.2008"
if isdate(d) then
wscript.echo "date is valid"
end if

Output:date is valid
(the output of isdate(d) is -1 if the date is valid and 0 of not)

DateAdd
to add an value to an existing date
Syntax: Date(DateInterval,number,date)
Example: wscript.echo dateadd("m",1,"10.12.2008")
Output: 10.01.2009 (the function adds one month to the existing date)

datediff
displays the difference between 2 dates
Syntax: Datediff(DateInterval,date1,date2)
Example: wscript.echo datediff("m","10.12.2008","10.03.2009")
Output: 3 (10.03.2009 minus 3 month is 10.12.2008)
the Variable Interval is the same as in dateadd

datepart
returns a part of a date
Syntax:datepart(DateInterval, date)
Example: wscript.echo datepart("m","10.12.2008")
Output: 12 (displays the month of the date)
the Variable Interval is the same as in dateadd

dateserial(year,month,day)
used to calculate a specific date
Example:wscript.echo Dateserial(2009-1,12-2,22-11)
Output:11.10.2008

datevalue
used to format the date, if the year is left it uses the systemdate to complete an date:
Example: wscript.echo Datevalue("10-12")
Output: 10.12.2008

day
returns the day of an date (values between 1-31)
Example:wscript.echo day("10.12.2008")
Output:10

month
returns the month of an date (values between 1-12)
Example:wscript.echo month("10.12.2008")
Output:12

year
returns the year of an date
Example:wscript.echo year("10.12.2008")
Output:2008

monthname
returns the month of an date (values between January and December)
Example:wscript.echo monthname("8")
Output:August

hour
returns the hour of an time (values between 0-23)
Example:wscript.echo hour("20:24:00")
Output:20

minute
returns the minute of an time (values between 0-59)
Example:wscript.echo minute("20:24:00")
Output:24

second
returns the second of an time (values between 0-59)
Example:wscript.echo second("20:24:12")
Output:12

formatdatetime
Syntax: formatdatetime(date,format)
Example: wscript.echo formatdatetime(date,1)
Output: Mittwoch, 10. Dezember 2008 (long date format)
Example: wscript.echo formatdatetime(date,2)
Output: 10.12.2008 (short date format)
Example: wscript.echo formatdatetime(time,3)
Output: 20:30:34(displays a time using hh:mm:ss)
Example: wscript.echo formatdatetime(time,4)
Output: 20:30 (displays a time using hh:mm)

timer
returns the seconds since 0:00
Example: wscript.echo timer
Output: 44743,62 (Uhrzeit: 12:25.43)

TimeSerial
used to calculate a specific time
Example:wscript.echo timeserial(22-11,12-2,22-11)
Output:11:10:11

TimeValue
used to format the time
Example: wscript.echo timevalue("13:12")
Output: 13:12:00

Weekday
Example: wscript.echo (Weekday(Date))
Output: 2 (2=Monday)
1=Sunday; 2=Monday; 3=Tuesday; 4=Wednesday; 5= Thursday; 6=Friday; 7= Saturday

Weekdayname
converts the numeric Weekday into the Name:
Example: wscript.echo (Weekday(2))
Output: Monday
1=Sunday; 2=Monday; 3=Tuesday; 4=Wednesday; 5= Thursday; 6=Friday; 7= Saturday
vbscript Array Functions - Syntax Reference >>>


new article

Search on this page
26.04.2018 03:50 now 1 Reader online