471,338 Members | 1,509 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

Date & DateTime datatypes format

Ed
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.

Thanx
Jul 21 '05 #1
3 1951
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
Jul 21 '05 #2
My problem is the following: When I assign a custom formatted Date & Time to
a Date variable it loses it’s formatting.
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.

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


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
Please reply only to the newsgroup.
Jul 21 '05 #3
Ed <Ed@discussions.microsoft.com> wrote:
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
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.
The same code work flawlessly on various other machines, thus I presume this
is settings related.


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

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Jul 21 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Andy Fish | last post: by
3 posts views Thread by J. Muenchbourg | last post: by
4 posts views Thread by Robert Scarborough | last post: by
2 posts views Thread by [Yosi] | last post: by
3 posts views Thread by Ed | last post: by
2 posts views Thread by John A Grandy | last post: by
2 posts views Thread by Bill Nguyen | last post: by
4 posts views Thread by Terry | last post: by
6 posts views Thread by Mark | 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.