Dates and Times
Submitted by joken on Tuesday, October 22, 2013 - 08:30.
One module in Visual Basic is DateAndTime . Which contains date values, time values, or date and time values. As a programmer, there are cases that we always display the date and time in our application or web application. Using visual basic we can manipulate dates and times in many ways. To do this, open and visual basic and create a new project and save it as “Datetime”. And add a button to our form, then double click it and add the following code.
The first line of code, it simply prints out the current Date and Time according to your PC.
10/21/2013 10;37:23 AM
Next line, it displays the long format of date as a string and we don’t display them because we did not specify it.
Monday, October 21, 2013
Next line, it displays the short format of date as a string.
10/21/2013
The next line will simply print out the current day.
Monday
Then the next line of code will display the year. And you can do this also same on how we display the current day by specifying the MMMM instead of dddd for correct typecasting.
2013
Then for the Next line of code, it adds thirty days so the out should look like as shown below.
11/20/2013 10;37:23 Am
Next, it displays the time in a long format.
10;37:23 AM
This gets the time in 12 hour format and also displays AM and PM.
10;37:23 AM
In the next line of code, we extract the hour.
10
For Minutes
37
And for Seconds
23
Take note, using Visual Basic are easy and there are many ways to manipulate the Dates and Time and this tutorial is just only serves as an eye opener to the wide world of programming.
Comments
Add new comment
- Add new comment
- 312 views