Function PDTtoIST(r As String) As String
Dim d, dv
d = Split(r)
dv = DateValue(d(1) & " " & d(2) & " " & d(5)) + TimeValue(d(3))
dv = DateAdd("n", 1470, dv)
PSTtoIST = Format(dv, "ddd mmm dd hh:mm:ss ""IST"" yyyy")
End Function
I am wondering if Scott's code will always work correctly for you? Your thread title indicates the date/time being converted could be either daylight saving time or standard time and that the date/time it is being converted to is always standard date/time. Scot's code does not handle both standard and daylight saving time as the value to convert from. Did you really need to distinguish between the two? If so, are you really only converting to a standard time value only? I would also note that although Scott's function is named to suggest it is converting standard time to standard time, it appears to actually be converting daylight savings time to standard time as that is what your Example/Result says your two times are.Amazing....works fine.
Function PTtoIST(r As String) As String
Dim d, dv
d = Split(r)
dv = DateValue(d(1) & " " & d(2) & " " & d(5)) + TimeValue(d(3))
dv = DateAdd("n", IIf(d(4) = "PDT", 1470, 1530), dv)
PTtoIST = Format(dv, "ddd mmm dd hh:mm:ss ""IST"" yyyy")
End Function
Excel 2010 | ||||
---|---|---|---|---|
A | B | |||
1 | Tue Jun 30 11:30:00 PDT 2015 | Wed Jul 01 12:00:00 IST 2015 | ||
2 | Tue Jun 30 11:30:00 PST 2015 | Wed Jul 01 13:00:00 IST 2015 | ||
Sheet1 |
Cell Formulas | ||
---|---|---|
Range | Formula | |
B1 | =PTtoIST(A1) | |
B2 | =PTtoIST(A2) |