Hi,
I would like to get dd/mm/yy 23:59 format of my date in the text box in aspx.cs code.
First, I select the date from the database into textbox as dd/mm/yy hh:mi, and then
I have to transform it to dd/mm/yy 23:59
Now I do this with this code
string MyDate //which I get from the function and then
textbox1.Text = MyDate.Remove(9)+ "23:59";
Do you know some better solution to do the same but without remove ?
Also, when user insert date like dd/mm/yy without hh:mm, I would like to change it to
"dd/mm/yy 23:59".
How can I check whether the hh:mm part is not inserted ?
Thanks a lot !
VinniePosted Sep 5, 2007, 4:38 AM
Yes, this is working :)
Thanks a lot !
AlanPosted Sep 5, 2007, 4:30 AM
The 'mm' needs to be in upper case for months to distinguish it from the minutes component of the DateTime object. This worked fine when I just tried it:
DateTime dt = DateTime.Now;
string myDate = dt.ToString("dd/MM/yy 23:59"));
VinniePosted Sep 5, 2007, 3:52 AM
Sam, thanks a lot !
Still, mydate.ToString("dd/mm/yy 23:59") doesn't work. I had a lot of problems with formating mydate "yyyy-mm-dd hh:mm" to "dd/mm/yy hh:mm", so I expected this :)
VinniePosted Sep 5, 2007, 3:51 AM
Sam, thanks a lot !
Still, mydate.ToString("dd/mm/yy 23:59") doesn't work. I had a lot of problems with formating mydate "yyyy-mm-dd hh:mm" to "dd/mm/yy hh:mm", so I expected this :)
SamPosted Sep 4, 2007, 3:16 PM
Hi,
If possible you should use the DateTime type instead of string to store the Dates and Times.
To convert a DateTime to a string in the format dd/mm/yy 23:59 try
MyDate.ToString("dd/mm/yy 23:59)
As for seeing if the time has been supplied in a string you could try
DateTime MyDate = DateTime.Parse(TheUsersString);
if (MyDate.TimeOfDay.TotalHours == 0d)
{
MyDate.AddHours(23);
MyDate.AddMinutes(59);
}
Hope this helps,
Sam.