Date time functions in vb script
It is very important that you know how to work with date and time in VBScript as most of the VBScript programs will have date and time involved in it.
Below is the list of all date and time functions in vb script.
First argument is Interval Type and it can be of below types.
yyyy - Year
m - Month
d - Day
h - Hour
n - Minute
s - Second
Below is the list of all date and time functions in vb script.
- date
- dateadd
- datediff
- datepart
- dateserial
- datevalue
- day
- hour
- minute
- second
- month
- monthname
- time
- timeserial
- timevalue
- weekday
- weekdayname
- year
We are going to have a look at each of these functions and examples in VBScript.
'To find current system date msgbox " Current System date is -> " & date '**************************************************************************** 'To find the future or past date msgbox "Tommorrow's date will be " & dateadd("d",1,date)
yyyy - Year
m - Month
d - Day
h - Hour
n - Minute
s - Second
'****************************************************************************
'To find the difference between 2 dates msgbox "Day Difference between today and tommorrow is " & datediff("yyyy","9-jan-1986",date)
First argument is Interval Type and it can be of below types.
yyyy - Year
m - Month
d - Day
h - Hour
n - Minute
s - Second
yyyy - Year
m - Month
d - Day
h - Hour
n - Minute
s - Second
'****************************************************************************
'To find the current day like 1,2,3...28 msgbox "Current day is -> " & day(date) '**************************************************************************** 'To find the current hour msgbox "current hour is -> " & hour(now) '**************************************************************************** 'To find the current minute msgbox "current minute is -> " & minute(now) '**************************************************************************** 'To find the current second msgbox "current second is -> " & second(now) '**************************************************************************** 'To find the current month number like 1,2....11,12 msgbox "current month is -> " & month(now) '**************************************************************************** 'To find the month name like Jan, Feb.....Dec msgbox "current month name is -> " & monthname(month(now)) '**************************************************************************** 'To find the current system time msgbox "current time is -> " & time '**************************************************************************** 'To find the weekday number like 1,2....7 msgbox "current weekday is -> " & weekday(now) '**************************************************************************** 'To find the name of week day like sunday, monday...saturday msgbox "current weekday Name is -> " & weekdayname(weekday(now)) '**************************************************************************** 'To find the current year msgbox "current year is ->" & year(now) '**************************************************************************** 'To find the parts of the given time stamp .equivalent to day, minute,hour, second etc msgbox "Day part of the current timestamp" & datepart("d",now) '**************************************************************************** 'To convert the string to date msgbox "String to date -> " & datevalue("09-jan-1986") '**************************************************************************** 'To convert the string to time msgbox "String to time-> " & TimeValue("7:15:49 PM") '**************************************************************************** 'To create date from numbers msgbox dateserial(1986,01,09) '**************************************************************************** 'To create time from numbers msgbox timeserial(17,01,09) '****************************************************************************
0 comments:
Post a Comment