0

How can I retrieve date and time from DateTime string?

DateTime datefrom = 8/27/2012 12:08:25 AM 

I want to retrieve only the date into one variable and only the time (with AM/PM) into another variable.

I want something like this:

string date = 8/27/2012 string time = 12:08:25 AM 
0

2 Answers 2

4

Use this:

 string date = dateform.ToString("MM/dd/yy"); string time = dateform.ToString("hh:mm:ss tt"); MM - month dd - day yy - year, can also use yyyy if you want it with 4 numbers hh - hour mm - minute ss - second t - one letter as in AM -> A and PM - P tt - two letters AM/PM 
Sign up to request clarification or add additional context in comments.

Comments

2

You can use Date and timeOfDay properties

//Date dateform.Date; //Time dateform.TimeOfDay; 

You can use ToString in order to format

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.