Click here to Skip to main content
15,881,044 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am Creating Date & Time Calculator in vb.net. I want to add Hours, Minute, Second in Date which is selected in datetimepicker1 and time which is in in other datetimepicket2. How to add time?

For Example,

Selected Date: 13-Mar-14 (Datetimepicker1)
Selected Time: 9:15:00 AM (Datetimepicker2)

Now I want to add "24 Hours 30 Minute 00 Seconds"(Textbox1, Textbox2, Textbox3)

My Answer Will be "14-Mar-14 9:45:00"

How can I do it? Help me....
Posted
Comments
Ramug10 7-Mar-14 5:13am    
show me your code...

Please see:
DateTime Structure[^]
especially the AddDays(), AddHours(), AddMinutes() and AddSeconds() methods, that should bring you everything you need for your task.

There is also another way to add 'something' to a DateTime: it is a TimeSpan, which holds the notion of a duration in time and natively supports basic arithmetic operations with a DateTime object. Example:
C#
DateTime myDate = new DateTime(2014, 3, 7, 11, 12, 00);
TimeSpan ts = TimeSpan.FromHours(1);
myDate += ts; // Here myDate variable will hold the DateTime value 2014, March 7th, 12:12:00


Hope this helps.
 
Share this answer
 
Comments
Lisa Sosa 7-Mar-14 7:12am    
Its Working Thanks...
First of all create a date from your selected date and time, and add hours and minutes to it, it will return new date accordingly....


VB
Dim strdatetime As String = String.Format("{0} {1}", "13-Mar-14", "9:15:00 AM")
Dim Date1 As DateTime = Convert.ToDateTime(strdatetime)

Date1 = Date1.AddHours(24).AddMinutes(30)

Dim newdatetime = Date1.ToString()
 
Share this answer
 
Comments
Lisa Sosa 7-Mar-14 7:11am    
Its Working Thanks....
Tejas Vaishnav 7-Mar-14 7:22am    
if its help you, please up vote my 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