rgn2121
asked on
How to show a DateTime value as 24 hour?
I am curious if there is a way to show a DateTime value as 24 hour. I know I can take a string formatted as 24 hour and turn it into a DateTime value, but it then converts it to standard time.
If I have a string = "5/01/2009 23:42:15" and I do a DateTime.Parse() on this value I get
#5/01/2009 11:42:15 PM#. Is there a way for me to get #5/01/2009 23:42:15 PM# or veen better
#5/01/2009 23:42:15# without the PM or AM...?
If I have a string = "5/01/2009 23:42:15" and I do a DateTime.Parse() on this value I get
#5/01/2009 11:42:15 PM#. Is there a way for me to get #5/01/2009 23:42:15 PM# or veen better
#5/01/2009 23:42:15# without the PM or AM...?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Looks like all that does it what I already know and that is formatting it into a String that shows it as 24 hour. I am curious if there is a way so that when my DateTime variable gets the date that when I hover over it in debug mode it shows me a date denoted by ## and shows it in 24 hour notation.
I am using the dates in DataTable and I am converting back anf forth from strings to dates when I have to do anything with Time where sorting and filtering are concerned. I would like to store them as dates and when they are displayed on reports and in Grids, they will show as 24 hour.
I am using the dates in DataTable and I am converting back anf forth from strings to dates when I have to do anything with Time where sorting and filtering are concerned. I would like to store them as dates and when they are displayed on reports and in Grids, they will show as 24 hour.
ASKER
So if I do somethine like what I have below and dump that to a datatable, then it will show in a grid as 24 hour time?
dim d as New DateTime
d = formatdatetime("5/01/2009 22:35:12")
ASKER
I will be away from this until later this afternoon, but I will follow up..
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
What kind of grid you want to show that information with that format ?
ASKER
I currently just dump all data, about 2500 rows and 40 columns, to a DataGridView. It really is used just while the application is in development right now. I might add something in later to make it part of the app in a logical place, but for now I just use it to check the data.
I use crystal reports though for all my reporting and I need to be able to show these DateTime values as just the time portion of HH:mm:ss. The reports are generated nightly so the actual date portion is understood by the user...and witht he amount of data I need to fit on a report, I don't really have room to show a bunch of identical dates.
oobayly>> Thanks for the code, That is what I currently use to store them in the tables now. I really wanted to store them as dates for the easy of filtering and such. I will have to look at the formatting for the columns...
I am not sure if there is a format available to alter the dates in Crystal, but I think I can work around it by making it a string...
Thoughts?
I use crystal reports though for all my reporting and I need to be able to show these DateTime values as just the time portion of HH:mm:ss. The reports are generated nightly so the actual date portion is understood by the user...and witht he amount of data I need to fit on a report, I don't really have room to show a bunch of identical dates.
oobayly>> Thanks for the code, That is what I currently use to store them in the tables now. I really wanted to store them as dates for the easy of filtering and such. I will have to look at the formatting for the columns...
I am not sure if there is a format available to alter the dates in Crystal, but I think I can work around it by making it a string...
Thoughts?
ASKER
Maybe I should add my systems default is not 24hour...I am going through a copy of my app now removing where I formatted the dates as strings...
ASKER
Okay...I think I can go with the dates, but I do have one issue. declare and instantiate a new DateTime object, I set it's value to 1001,01,01,0,0,0. I thought, I guess incorrectly, that DateTime.MinValue was #01/01/1001 00:00:00# as opposed to just #12:00:00 AM#.
I have a class that I created that has numerous DateTime objects. When they are initially created they get the value of 1001,01,01,0,0,0. I have a function I use to clear all of the variables in my class after it hase been added to a DataTable. In that function I se the values of my DateTime objects to DateTime.MinValue. This way I can check for it later they same way I was setting the string values to String.Empty and using String.IsNullorEmpty().
I know that I can return 01/01/1001 as a string from DateTime.MinValue by using the ToShortDateString(), but I want it as a date since that is what my variables are now.
I have a class that I created that has numerous DateTime objects. When they are initially created they get the value of 1001,01,01,0,0,0. I have a function I use to clear all of the variables in my class after it hase been added to a DataTable. In that function I se the values of my DateTime objects to DateTime.MinValue. This way I can check for it later they same way I was setting the string values to String.Empty and using String.IsNullorEmpty().
I know that I can return 01/01/1001 as a string from DateTime.MinValue by using the ToShortDateString(), but I want it as a date since that is what my variables are now.
ASKER
Seems like DateTime.MaxValue gives me a Date and a Time where as DateTime.MinValue just gives me a Time...
ASKER
Sorry for all the posts...I work nights.
ASKER
I have gotten around the DateTime.MinValue by using
DateTime.Parse("01/01/1001 00:00:00") in its place.
DateTime.Parse("01/01/1001
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Sorry...I have worked through this a lot tonight, so you can disregard the comments about the format. Going off of oobayly's comment about formatting the columns of the grid, I finally found what you just listed above.
I am getting ready to get into the Crystal Reports and correct them to work with these dates instead of the strings I was using before.
The problem I mentioned about the DateTime.MinValue I think I have fixed. If you had trouble understanding that portion I can explain what I meant and we can see if what I did was a good idea. Seems very logical and the data is accurate so I think I am good...
I am getting ready to get into the Crystal Reports and correct them to work with these dates instead of the strings I was using before.
The problem I mentioned about the DateTime.MinValue I think I have fixed. If you had trouble understanding that portion I can explain what I meant and we can see if what I did was a good idea. Seems very logical and the data is accurate so I think I am good...
ASKER
I am going to go ahead and award points as I think the original question has been handled. I will explain what I did if either of you care, other wise I will post a new question if I have issues with the CR.
Thanks for all the help...I learned a lot, which is what I was hoping for...
Thanks for all the help...I learned a lot, which is what I was hoping for...
http://www.astahost.com/info.php/question-about-asp-now-function_t7186.html
Cheers,
Bob