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
 

Some videos you may like

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"

FormR

MrExcel MVP
Joined
Aug 18, 2011
Messages
6,408
Office Version
365
Platform
Windows
Hi, DateValue() returns the date portion of the string only - try with cdate() instead - for example:

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

Watch MrExcel Video

Forum statistics

Threads
1,100,206
Messages
5,473,157
Members
406,849
Latest member
AndreasMs

This Week's Hot Topics

Top