Thursday, January 3, 2019


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.
  1. date
  2. dateadd
  3. datediff
  4. datepart
  5. dateserial
  6. datevalue
  7. day
  8. hour
  9. minute
  10. second
  11. month
  12. monthname
  13. time
  14. timeserial
  15. timevalue
  16. weekday
  17. weekdayname
  18. 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)

First argument is Interval Type and it can be of below types.

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
'****************************************************************************
'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)
'****************************************************************************



Related Posts:

  • Classes in VBScript Classes in VBScript Here is an example that shows how we can create a class in QTP. Once we define the class, we can create its objects and then access its method and properties. 'declare the class book. Class Bo… Read More
  • Error handling in VBScript Error handling in VBScript VBScript provides below statements and keywords to handle errors. on error resume next Err object - err.description, err.number Sample code to handle the error is given below If er… Read More
  • What are the different operators in vbscript? What are the different operators in vbscript? At broad level there are 3 kinds of operators as mentioned below. Arithmetic Operators Comparison Operators Logical Operators Arithmetic Operators in the order of pre… Read More
  • Date time functions in vb script 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 … Read More
  • How we can define array in vb script How we can define array in vb script Arrays are used to store multiple values in the same variable.We can define array in vb script in 4 different ways. dim a(10)  - static array of 11 elements dim b()  … Read More

0 comments:

Post a Comment

Blog Archive

Translate

Popular Posts

Total Pageviews

150,592

Blog Archive