Groups | Blog | Home
all groups > dotnet general > june 2005 >

dotnet general : Date & DateTime datatypes format


Ed
6/7/2005 11:28:01 PM
Hi there,

My problem is the following: When I assign a custom formatted Date & Time to
a Date variable it loses it’s formatting. Ex. 2005-06-07 15:46
[Format(Now(), "yyyy-MM-dd HH:mm")] now when I assign this to a variable of
type Date or DateTime this becomes 2005/06/07 03:46:00

The same code work flawlessly on various other machines, thus I presume this
is settings related. I know that the Time function in VB.NET reads from the
system time, which you set in Regional Settings under the Control Panel. I
did try to change the settings but it did not seem to work, unless I'm not
setting it up correctly.

Any ideas would be appreciated.

Mattias Sjögren
6/8/2005 12:00:00 AM

[quoted text, click to view]

Why do you assign it to a Date _after_ you perform the formatting? If
you have Option Strict turned on you shouldn't even be allowed to
assign a String to a Date like that.


[quoted text, click to view]

A Date (or DateTime) variable doesn't carry any formatting
information. You can display it in whatever format you want with the
Format function or DateTime.ToString().



Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Jon Skeet [C# MVP]
6/8/2005 12:00:00 AM
[quoted text, click to view]

Yes, in the same way that if you parsed a string saying "10.00000" as a
double, you wouldn't keep the formatting from that either. The format
isn't any part of the DateTime logically - an instant in time doesn't
have a format associated with it any more than a number does.

[quoted text, click to view]

Well, it would "work flawlessly" if the format you used happened to be
the system default one...

--
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet
Cor Ligthert
6/8/2005 12:04:58 PM
Ed,

Showing samples whith dates that can mean 6 july or june 7 is in my opinion
not the best way to show a problem. Can you show it with a date as december
31.

Cor

AddThis Social Bookmark Button