Reputation: 11
I'm currently using this,
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
Sheets("Sheet1").Range("K1").Value = Format(Now(), "mm-dd-yyyy")
End Sub
in order to print the last save to my spreadsheet. What I would like to do however is have it print the date from 12 hours ago. Would this require a simple change to the code or something else entirely?
Upvotes: 1
Views: 57
Reputation: 544
I would use the DateAdd function:
Sheets("Sheet1").Range("K1").Value = DateAdd("h", -12, Now())
Upvotes: 1
Reputation: 19727
Just like what pnuts commented, you should subtract the hours from Now
.
Try:
Sheets("Sheet1").Range("K1").Value = Format(Now - TimeValue("12:00"), "mm-dd-yyyy")
Upvotes: 0