Syntax to add the time without the date

Dheepak

Board Regular
Joined
Aug 25, 2013
Messages
64
Hi,

Using Now() function i have displayed the date and time in cells(4,1) as 2/10/2015 15:20. However, in next cell i need to display the time with the addition of 2hrs without changing the format. I'm getting time mismatch error if i use the below code.

Code:
Cells(38, 8) = Now() + Time(2, 0, 0)

can anyone please let me know how to get display the output as 2/10/2015 17:20.

Thanks in advance.

Regards,
Dheepak.
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
Thanks a lot, steve.!!!!!!! i got the expected output.. Thank you so much :)

Best Regards,
Dheepak
 
Upvote 0
Thank you so much, hippiehacker. Both the codes are giving the same result as expected. Thank you much :)

Best Regards,
Dheepak
 
Upvote 0
Hi,

Using Now() function i have displayed the date and time in cells(4,1) as 2/10/2015 15:20. However, in next cell i need to display the time with the addition of 2hrs without changing the format. I'm getting time mismatch error if i use the below code.

Code:
Cells(38, 8) = Now() + Time(2, 0, 0)

can anyone please let me know how to get display the output as 2/10/2015 17:20.
Time, the way you are trying to use it, is an Excel worksheet function... VB's TimeSerial function is its equivalent...

Cells(38, 8) = Now() + TimeSerial(2, 0, 0)

Note: The reason for the particular error you got is because VB has a Time() function, but it takes no arguments (the arguments you tried to pass is what generated the error) and it returns the current computer system's time value. You can also use Time as a statement and set your computer system's time with it.
 
Upvote 0
Thank you so much, Rick for providing the background of the error. Now, I can able to differentiate and understood the mistake that happen in the code. Thank you once again :)

Best Regards,
Dheepak
 
Upvote 0

Forum statistics

Threads
1,223,230
Messages
6,170,883
Members
452,364
Latest member
springate

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top