By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,854 Members | 869 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,854 IT Pros & Developers. It's quick & easy.

How to initial the datetime value to "01/01/2005 00:00:00"?

P: n/a
ABC
How to initial the datetime variable as value to "01/01/2005 00:00:00"?
Dec 19 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
You can do this manually like below in JS..
Of course you can do the same thing in cSharp DateTime class.

var now=new Date();
var wanted=format(now);
function format(now)
{
return
now.getDay()+"/"+now.getMonth()+"/"+now.getFullYear(); // you can add
now.getHours or getMinutes...
}

Dec 19 '05 #2

P: n/a
"ABC" <ab*@abc.com> wrote in news:es**************@TK2MSFTNGP15.phx.gbl:
How to initial the datetime variable as value to "01/01/2005 00:00:00"?


You can use the constructor that allows you to specify each of the values:

[C#]
public DateTime(
int year,
int month,
int day,
int hour,
int minute,
int second
);

so you would say:

DateTime dt = new DateTime(2005, 1, 1, 0, 0, 0);

-mdb
Dec 19 '05 #3

P: n/a
DateTime.Parse("01/01/2005 00:00:00")

ABC wrote:
How to initial the datetime variable as value to "01/01/2005 00:00:00"?


Dec 19 '05 #4

P: n/a
Brian Gideon <br*********@yahoo.com> wrote:
DateTime.Parse("01/01/2005 00:00:00")


I'd advise against this solution. It's very inefficient to use string
parsing when you can specify the parts explicitly with a constructor.
The above might also fail in some cultures (although I don't know of
any where it would fail offhand).

I'd suggest using:

DateTime dt = new DateTime (2005, 1, 1);

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Dec 20 '05 #5

P: n/a
Yep. I don't disagree with that suggestion, but since it was already
mentioned I thought I'd provide an alternate method that might be
helpful if the date was stored as a string which I thought, based on
the subject, was the intent of the OP :)

Brian

Jon wrote:
Brian Gideon <br*********@yahoo.com> wrote:
DateTime.Parse("01/01/2005 00:00:00")


I'd advise against this solution. It's very inefficient to use string
parsing when you can specify the parts explicitly with a constructor.
The above might also fail in some cultures (although I don't know of
any where it would fail offhand).

I'd suggest using:

DateTime dt = new DateTime (2005, 1, 1);

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too


Dec 20 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.