This post has been edited by Henningfeld: 09 August 2010 - 12:22 PM
Date and Times in C#
Page 1 of 13 Replies - 1337 Views - Last Post: 09 August 2010 - 12:37 PM
#1
Date and Times in C#
Posted 09 August 2010 - 12:12 PM
I have never tried to do anything like this before and I'm having a hard time seeing on a good path to do so. I have two date pickers ones is where the users will select a date such as 8/9/2010 and another where a user will select a time such as 2:11 P:M. I want to some how combine these two into one date in the back end. I have a date different funcation and would like to combine this date and time together to use it in a function there fore when I pass it I would like for it to be 8/9/2010 2:11 P:M.
Replies To: Date and Times in C#
#2
Re: Date and Times in C#
Posted 09 August 2010 - 12:19 PM
try this...
I didn't test this code, but you can try it to see if it gives you what you want.
DateTime date = datePicker.Value; DateTime time = timePicker.Value; DateTime selectedDate = new DateTime(date.Month, date.Day, date.Year, time.Hour, time.Minute, time.Second); MessageBox.Show(selectedDate.ToString());
I didn't test this code, but you can try it to see if it gives you what you want.
#3
Re: Date and Times in C#
Posted 09 August 2010 - 12:20 PM
Well, if you have two DateTimes, you can do something like this:
DateTime date = new DateTime(2010, 8, 9, 0, 0, 0);
DateTime time = new DateTime(2010, 1, 1, 8, 30, 0);
string newDate = string.Format("{0} {1}",
date.ToString("MM/dd/yyyy"),
time.ToString("HH:mm"));
DateTime myNewDate = DateTime.Parse(newDate);
Console.WriteLine(myNewDate.ToString());
//output is 8/9/2010 8:30:00 AM
Console.ReadKey();
This post has been edited by insertAlias: 09 August 2010 - 12:21 PM
#4
Re: Date and Times in C#
Posted 09 August 2010 - 12:37 PM
Thanks to both of you. I was making it more diffuclt then what it needed to be.
Page 1 of 1
|
|

New Topic/Question
Reply




MultiQuote



|