Visual Basic: dates and times [Archive] - SpeedGuide.net Broadband Community

View Full Version : Visual Basic: dates and times


athalonxpkid
03-04-02, 10:30 PM
hi, i need to know how i can store the three parts of a date e.g.(month, day , year) into three separate variables, MM, DD, and YYYY. i would like these to be stored upon formload, any help is of great help. thanx. Nate Mccorkle

4oh4
03-05-02, 01:55 AM
Vb's got a ton of date related functions. You don't have to write a function to parse the current date in order to separate the day, month, or year. Instead just use the "Day", "Month" (or even "MonthName"), and "Year" functions. So it'd be like:
(assuming you're using option explicit)

dim intDay as integer
dim intMonth as integer
dim szMonthName as string
dim intYear as integer

intDay = Day(now)
intMonth = Month(now)
szMonthName = MonthName(month(now),false) ;false to abbreviate the month
intYear = Year(now)

;then do whatever you want with those values
;depending on how you want the month value to be stored....
;I gave two examples. Of course, you'll most likely only need one
;of those


edit:
Actually I think "false" doesn't abbreviate the month in the "MonthName" function.

athalonxpkid
03-05-02, 06:13 PM
k i have already found anoter way, using datePart()

thanx anyway

4oh4
03-05-02, 11:30 PM
The "DatePart" function is another way of doing it. Like I said, vb's got a ton of date related functions.

The reason why I chose the functions that I did in my previous post, is that was the most flexible way to do what you wanted to do. Feel free to go whichever route that you want to go.

Just remember that if you don't FULLY understand why and how your code does what it does (in whatever language you choose to code in, and whoever wrote the code that you're using) then you're not progressing at all.

athalonxpkid
03-06-02, 12:34 AM
thanx again.... i decree this thread closed.... though i'm not sure how to actually do it