Click here to Skip to main content
15,911,711 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have Entered a date using datetime picker and its data type in database is also datetime.I have to fetch that date and display it separately in two columns ie to split it (date and time seperately ).How to do???
Posted

go through this link
Here[^]
for Datetime formats

Thanks
--RA
 
Share this answer
 
Comments
shilpa sonawane 30-Jan-12 6:11am    
I know that I want the output like for eg datetime is "1/18/2012 12:00:00 Am" I want to split that date while printing datagrid into "1/18/2012" as date in date column and 12:00:00Am as time
Hi,

Try the below code.
Date:
C#
string theDate = dateTimePicker1.Value.ToShortDateString();

or, if you'd like to specify the format of the date:

C#
string theDate = dateTimePicker1.Value.ToString("yyyy-MM-dd");


Time:
TimeSpan tmtimestamp= DateTimePicker1.Value.TimeOfDay();


Hope this helps.
 
Share this answer
 
v2

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