Select Page
Codoid Blog

Date and Time

Being a leading QA Company, we write blogs on all prominent software testing topics and tools using our real-world experience. So stay sharp by subscribing to our Newsletter.

please put a short text here please put a short text here please put a short text here please put a short text here please put a short text here

Comparing dates and times

Dim dtDate1_dtDate1=Cdate("08/01/2009 12:00AM")
Dim dtDate2_dtDate2=Cdate("08/01/2009 12:00AM")

Dim dateTime:Set dateTime=DotNetFactory.CreateInstance("System.DateTime")

Msgbox dateTime.Compare(strDate1,strDate2)
'If dates are equal, then result will be 0.
  

 

Parsing String Representation of a date

Dim dateTime:Set dateTime=DotNetFactory.CreateInstance("System.DateTime")

Msgbox dateTime.Parse("Dec 03, 2003 12:00:00 PM")
'The output will be 12/3/2003 12:00:00 PM
  

 

Checking whether the year is leap year or not

Msgbox dateTime.IsLeapYear(1997)
'It will return True, if the year is a leap year else false.
  

 

Adding and Subtracting days

Dim dateTime:Set
dateTime=DotNetFactory.CreateInstance("System.DateTime","",1996,8,3)
'The date is set while creating DateTime insyance with three constructors
(year,month & day)

Msgbox dateTime.AddDays(2)'Adding two days

Msgbox dateTime.AddDays(-1)'Subtracting one day
  

 

Formatting a date

Dim dateTime:Set dateTime=DotNetFactory.CreateInstance("System.DateTime")

Msgbox dateTime.Now.ToString("MMM ddd d HH:mm yyyy")
  

 

Getting Short and Long Date

Msgbox dateTime.Now.ToLongDateString()'Long date

Msgbox dateTime.Now.ToShortDateString()'Short date
  

 

Displaying AM or PM FROM a date

Msgbox dateTime.Now.ToString("tt ")
'The output will be AM or PM
  

Comments(0)

Submit a Comment

Your email address will not be published. Required fields are marked *

Talk to our Experts

Amazing clients who
trust us


poloatto
ABB
polaris
ooredo
stryker
mobility