Current Time +2 Hours (keep min and second from Original Time)

Andresuru

New Member
Joined
Sep 6, 2021
Messages
33
Office Version
  1. 365
Platform
  1. Windows
Hi Excel MVP Team,

Please note I am trying to add 2 hours for the current time keeping the minutes and second for the original time since I need to add a time stamp.

VBA Code:
Sub ChangeDateToTime()

'Track date of the Modified Date

Application.ScreenUpdating = False

With Sheets("TrackDate")

Y = Time

.Visible = True
.Range("D2").Value = Date & " " & Y
.Visible = xlSheetVeryHidden

Debug.Print Date & " " & Y


End With

End Sub

Result was 5/11/2022 10:48:37 AM
Result required : 5/11/2022 12:48:37 AM (Current Time +2 hours)

Appreciate your help as soon as possible since I checked many pages and I cannot find a solution.

Thank in advance'
Andres
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
Hi Guys,

I guess I find the solution but hopefully this thread will help another people.
It looks like the code works as this: I already check and gave the result required

VBA Code:
Sub ChangeDateToTime()

'Track date of the Modified Date

Application.ScreenUpdating = False

Dim LDate As Date
 
LDate = DateAdd("n", 120, Time())

With Sheets("TrackDate")

Y = Time

.Visible = True
.Range("D2").Value = Date & " " & LDate
.Visible = xlSheetVeryHidden

Debug.Print Date & " " & LDate


End With

End Sub

Regards
Andres
 
Upvote 0
Solution

Forum statistics

Threads
1,214,911
Messages
6,122,192
Members
449,072
Latest member
DW Draft

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