Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

When formatting date from a database it's returned as:

"2004/01/01 14:30", which is correct.

 

But when run from a different machine the time is messed up. Displayed as "02:30".

 

Checked regional settings on both machines and they match and formatting the time in .NET doesn't work. Can anyone help?

 

:mad: :mad:

Posted

That's the same time, but in 24 hour time.

 

On my project, I had to use strings rather than Date or Time. VERY frustrating.

 

In Access, you can make Date/Time and set it to ONLY be date. Same with Time.

 

Fine, thats what I needed.

 

When I bring it over to VB.Net through a DataAdaptor, it comes through as 04/22/2004 00:00am, even though its ONLY the Date.

 

Because of issues like these I had to use strings to hold the date and times in a database. Very frustrating, but I need to have returned what I put in, not extra garbage. Someday I'd like to find a workaround :)

  • *Experts*
Posted

A general rule of thumb is store date/time (even if it's just a Date) in a DateTime variable in your program. Only when you want to display it do you format it. You can use the overrides on ToString() to "hardcode" a format if you like. For example, to not show the time portion:

string s = DateTime.Now.ToString("MM/dd/yyyy");

 

If you want a specific time format, or want to ensure that it's the same on every machine, it's probably best to use a "hardcoded" string format or use your own CultureInfo object to do the formatting.

 

-Nerseus

"I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...