Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello,

I have this datetime object:

C#
DateTime DateStart = dateTimePicker1.Value;

Now I'd like to set the picked date to a fixed hour, for instance 12u. So the format would look like 'yyyyMMddT12mm00'

This can be easily done by setting a string format. But my result has to be a DateTime object.

All help is appreciated!

Kind regards,
Christophe

What I have tried:

I've tried the string solution, but further in the code it has to be a DateTime
Posted
Updated 12-Jul-22 5:47am
v2
Comments
0x01AA 12-Jul-22 10:07am    
How is about to use the ctor public DateTime (int year, int month, int day, int hour, int minute, int second); to create your date/time object and pass year, month, day from the date picker and the hour, min and second according to your requirements?

1 solution

See also my comment to the question. If I understand your request correctly, something like below should do the job:

C#
DateTime DateStart = new DateTime(dateTimePicker1.Value.Year, dateTimePicker1.Value.Month, dateTimePicker1.Value.Day, 12, 0, 0);
 
Share this answer
 
Comments
Tinker-Bel 12-Jul-22 10:37am    
Yes, this is exactly what I would like to do!

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