Click here to Skip to main content
15,889,116 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
plz Please help me. In my project one field is 'CreatedOn' and in that saving date time. for that field in database it has datetime datatype and while saving it i am converting in into string as :

C#
hdfCreatedOn.Value = Convert.ToString(DateTime.Today); 

But it saves date as 2012-06-27 00:00:00.000 it not shows time.
Posted
Updated 27-Jun-12 0:54am
v3
Comments
Shahin Khorshidnia 27-Jun-12 6:53am    
1. Do not use sms words like "plz". You have enough time to type "Please". 2. Why don't you use DateTime.Now instead of Today?

Try using -
C#
hdfCreatedOn.Value = Convert.ToString(DateTime.Now);


For details go through this-
C# datetime-format[^]
 
Share this answer
 
v2
Comments
Vani Kulkarni 27-Jun-12 6:54am    
Ditto! :)
Vaishali P. Patil 27-Jun-12 6:55am    
thanks. it works
Jαved 27-Jun-12 6:55am    
:-)
Jαved 27-Jun-12 6:55am    
You are welcome. Accept as answer if you think it helped.
Vaishali P. Patil 27-Jun-12 6:57am    
by using this it shows formatt as 2012-06-27 16:24:39.000 i want to show 2012-06-27 4:28 PM
Try below code:

C#
hdfCreatedOn.Value = Convert.ToString(DateTime.Now); 
hdfCreatedOn.Value = String.Format("{0:g}", DateTime.Now);  // "6/27/2012 4:32 PM"
hdfCreatedOn.Value = String.Format("{0:G}", DateTime.Now);  // "6/27/2012 4:32:07 PM"
 
Share this answer
 
v5
Comments
Vaishali P. Patil 27-Jun-12 6:55am    
thanks it works
Mohamed Mitwalli 27-Jun-12 7:16am    
If it works with you , you should mark it as answer .

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900