From the course: Visual Basic Essential Training
Unlock this course with a free trial
Join today to access over 24,500 courses taught by industry experts.
Initialize date and time values - Visual Basic Tutorial
From the course: Visual Basic Essential Training
Initialize date and time values
- [Instructor] At some point, we'll need to initialize this variable and store the real value that we want for the date, so let's look at several ways we can do that. One is to assign a literal value like this. The delimiter in Visual Basic for date literals is the hash symbol or the pound sign. They go at the beginning and ending of the literal value. You can also use parse. As I mentioned earlier in this course, TryParse is the better solution. I'll show you TryParse in code later in this chapter. So the DateClass has a parse method on it, so I can go ahead and assign this like so. The Date.Parse method can interpret various strings. So here, I'm trying to parse it using the hyphen between the values. I can also use the slash in there and other symbols. So the DateClass itself will try to parse this string correctly. We can also use the constructor of the DateClass. We want to instantiate a new date, and then we're going to pass in, in this case, three arguments. I'm going to do…
Contents
-
-
-
-
-
-
-
-
-
-
(Locked)
The date types2m 27s
-
(Locked)
Define date and time variables1m 6s
-
(Locked)
Initialize date and time values4m 42s
-
(Locked)
Output formatted date values3m 50s
-
(Locked)
Date manipulation2m 14s
-
(Locked)
Challenge: Strings, dates, and parsing1m 47s
-
(Locked)
Solution: Strings, dates, and parsing2m 22s
-
(Locked)
-
-
-
-
-
-
-
-
-
-