DateAdd Not Working as Expected

patticlaire

New Member
Joined
Jun 15, 2018
Messages
6
Basically I'm just trying to convert a date and time to a different time zone. Here is my code:

Code:
dateString = Left(startcell.Offset(i, 0).Value, 10) & " " & Mid(startcell.Offset(i, 0).Value, 12, 5)
dateofPeak = DateAdd("h", -7, DateTime.DateValue(dateString))

The dateString input is "2018-06-02 20:00". Since I am trying to subtract 7 hours from the time to convert it to a different time zone, I would expect the output, dateofPeak, to be 6/2/2018 1:00:00 PM. However the output I actually get is 6/1/2018 5:00:00 PM.

Any idea what I'm doing wrong?? All the dates that go into the DateAdd function come out as the day before at 5PM. I'm very confused
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
Hi, DateValue() returns the date portion of the string only - try with cdate() instead - for example:

Code:
dateofPeak DateAdd("h", -7, CDate(dateString))
 
Upvote 0

Forum statistics

Threads
1,223,886
Messages
6,175,196
Members
452,616
Latest member
intern444

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