how do I get the current date from the computer?
Printable View
how do I get the current date from the computer?
One way...
MessageBox.Show(My.Computer.Clock.LocalTime.ToShortDateString)
Another way...
MessageBox.Show(System.DateTime.Today.ToShortDateString)
Thanks!!!
one related question, if the computers date format is changed, will it change
the formated date from this function?
It will eval to whatever the systems regional date/time settings are.
Yes it will. That function just grabs whatever is there.
ok. is there anyway to get the same format no matter what the computer is set to?
You could, however, try something like this if you require a specific formatvb.net Code:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Label1.Text = DateTime.Now.ToString("MM/dd/yyyy") End Sub
You can specify the format if you are worried that the system may use some different format then what you need to calculate with or ??
I am working on a database and I want to add the year to a new record when it is created.
Then your tables field's data type should be Date/Time.
Actually, I prefer storing dates as straight text, although I've discovered few agree with me. :D
Anyway, to retrieve the date, usevb.net Code:
DateTime.Today.Year.ToString
Yes, I disagree :D
Also, you mean to retrieve the Year ;)
Give me text or give me death! :D
My code snippet does return the current year.
.:p.Quote:
Originally Posted by Hack
Oh piffle.....he knew what I meant. :lol:
http://www.vbforums.com/Quote:
piffle
Can you read my mind too :D
Ps, :lol: I got the last word in :p ;)
the length will change.
12/5/2007
1/1/2007
12/12/2007
is string handling the only way to get the year, month, day??
Not really. You should just use each function to parse out what you need.
DateTime.Today.Month.ToString()
DateTime.Today.Day.ToString()
DateTime.Today.Year.ToString()
ok, i got it now.
thanks!!!!!!!!!!!!!
If you want the whole date, and not just the year, then wouldn't this work for you?Quote:
Originally Posted by Hack in Post # 7
yes, I will make an note of that.
this turns out to be what I need:
DateTime.Today.Month.ToString()
DateTime.Today.Day.ToString()
DateTime.Today.Year.ToString()
Just one final thing. I have seen this way too many times. If you are going to be storing the date, or the year, or something along those lines in DB fields, do you call the fields Year or Date or the like. Those are reserved words and should not be used for field names.
I am using: "IncidentYear"
:thumb: Outstanding. You, potentially, have saved yourself headaches when running queries against your tables. :)
Yes
no confusion this way