I was searching here about converting a string like "16:20" to a DateTime type without losing the format, I said I dont want to add dd/MM/yyy or seconds or AM/PM, because db just accept this format.
I tried with Cultures yet
Thanks in Advance
I was searching here about converting a string like "16:20" to a DateTime type without losing the format, I said I dont want to add dd/MM/yyy or seconds or AM/PM, because db just accept this format.
I tried with Cultures yet
Thanks in Advance
I want to address this part of your question:
A database will generally store all datetime values in a standard common format that's not even human readable. If you use a datetime column the original format is destroyed.
However, when you retrieve the value you cast it back to any format you want. If you want
HH:mm
you can get it.Since you don't stipulate which DBMS you are using, it is hard to know which answer will help you. If you use IBM Informix Dynamic Server, you would simply use the data type 'DATETIME HOUR TO MINUTE', which will record values in the 24 hour clock.
DateTime.Now.ToString("hh:mm") - If it's C#.
Oh. Only read the header.
Just give a date format to your dateTime.
string DateFormat = "yyyy MM d "
this willl give you the year month and day. after continuing;string DateFormat = "yyyy MM d HH:mm:ss "
in here the Capital H will give you the24 hours time format
and lowerCase"h" will give you the 12 hours time
format...when you give the Dateformat as a string you can do whatever you want with date and time.
OR
OUTPUT:
what do you mean by "losing the format".
if you convert it to a DateTime type, then the DateTime object will have dd/mm/yy and other properties. depending on how you plan to use the object, you can "recover" your original settings, by formatting the string output like this: DT.ToString("HH:mm");
All DateTime objects must have a date and a time.
If you want just the time, use TimeSpan:
If you want a DateTime, add that time to the min value: