I'm pulling into a variable a datetime value. Now, I want to post this value back to my database, but I need it to be only the year digits. How do I get VB.NET to trim the month, day, and time off and just return the four character year (e.g. 2011)?
I just had to do this for my VB program.
Dim Year As Integer
Year = Convert.ToInt32(Now.ToString("yyyy"))
Use just "yy"
if you want two digit year. Then, when you need to display it somewhere:
year.tostring
Date.Today.Year
is what you're looking for, or for an existing date, just someDateVariable.Year
i know this is a bit late to answer but, it wont hurt telling, try "year(now) " and load it to a variable Example:
Dim Year_in_Digits = Year(Now)
Dim myDate As DateTime = #1/1/2011#
Dim myYear As Int32 = myDate.Year
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With