471,321 Members | 1,784 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,321 software developers and data experts.

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

ABC
How to initial the datetime variable as value to "01/01/2005 00:00:00"?
Dec 19 '05 #1
5 1876
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
"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
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
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
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.

Similar topics

1 post views Thread by Francesc Guim Bernat | last post: by
11 posts views Thread by Robert Lacoste | last post: by
3 posts views Thread by _Christopher\(M2M\) | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.