Display Date
-
I want to display the year on a label on my form. How do you get the year from the date. I have tried this to no avail: Dim DateItem As Date Num.Text = d.Year.ToString() Num is the label name Anyone any ideas?
'this would get today's year num.text = Date.Now.Year.ToString so you need to set DateItem to a date before using it. dim DateItem as new date(2005,05,23) num.text = DateItem.Year.ToString
-
'this would get today's year num.text = Date.Now.Year.ToString so you need to set DateItem to a date before using it. dim DateItem as new date(2005,05,23) num.text = DateItem.Year.ToString
-
Chris, Thanks for the reply. Is it necessary to set the date as dim DateItem as new date(2005,05,23), could you not get the date from the system as System.Date ?
Here is what I've used in the past: label1.Text = CStr(Year(CDate(DateString))) Hope this helps :) Lost in the vast sea of .NET
-
Chris, Thanks for the reply. Is it necessary to set the date as dim DateItem as new date(2005,05,23), could you not get the date from the system as System.Date ?
No. All you need to get the current date is:
Dim myDate As Date = Date.Now()
RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
-
No. All you need to get the current date is:
Dim myDate As Date = Date.Now()
RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
-
No. All you need to get the current date is:
Dim myDate As Date = Date.Now()
RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
Thanks for the reply. That Anonymous posting was me also, I hadn't logged in, i logged in and reposted so you know who is posting. I realise the above code should bring back the date Now but how do I get the year from this date Now as it is bringing back the entire date?
-
Thanks for the reply. I realise this should bring back the date Now but how do I get the year from this date Now as it is bringing back the entire date?
-
I want to display the year on a label on my form. How do you get the year from the date. I have tried this to no avail: Dim DateItem As Date Num.Text = d.Year.ToString() Num is the label name Anyone any ideas?
Are you still having trouble getting the year from the date? Have you tried the following (this will get the current year): num.text = Date.Now.Year.ToString For example, today is May 23, 2005 Date.Now.Year.ToString --> will print 2005 Date.Now.Month.ToString --> will print 5 Date.Now.Day.ToString --> will print 23 If you want some other year (let's say you're parsing a date string) dim DateItem as Date = Date.Parse(dateString) num.text = DateItem.Year.ToString or num.text = Date.Parse(dateString).Year.ToString Hope this helps, Chris
-
Thanks for the reply. That Anonymous posting was me also, I hadn't logged in, i logged in and reposted so you know who is posting. I realise the above code should bring back the date Now but how do I get the year from this date Now as it is bringing back the entire date?
The Year property is an Integer, so it work just like any other Interger number.
Dim myDate As Date = Date.Now
Dim currentYear As Integer = myDate.Yearor, in a single line of code:
Dim currentYear As Integer = Date.Now.Year
Docs for the DateTime structure[^]
Now
is a static property that always returns the current Date and Time in a single DateTime structure. You could use theToday
static property to return just the date, but it still returns an entire DateTime structure, just with the time set to 00:00:00.0. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome -
I want to display the year on a label on my form. How do you get the year from the date. I have tried this to no avail: Dim DateItem As Date Num.Text = d.Year.ToString() Num is the label name Anyone any ideas?
Try this. Label1.Caption = Year(Date) George