Link to home
Start Free TrialLog in
Avatar of Andrew Angell
Andrew AngellFlag for United States of America

asked on

How to convert this time string so I can subtract 5 hours from it...???

AuctionStartGMT = "2006-07-23T04:22:50.776Z"
AuctionStartDate = (Left(AuctionStartGMT,10))
AuctionStartDateSplit = Split(AuctionStartDate, "-")
AuctionStartMo = AuctionStartDateSplit(1)
AuctionStartDay = AuctionStartDateSplit(2)
AuctionStartYear = AuctionStartDateSplit(0)
AuctionStartDate = AuctionStartMo&"/"&AuctionStartDay&"/"&AuctionStartYear
AuctionStartTimeGMT = Mid(AuctionStartGMT,12,8)
AuctionStartTimestamp = AuctionStartDate&" "&AuctionStartTimeGMT

What I've got there works to the extent of turning the original time/date format returned into what I want:  07/23/2006 04:22:50

I need to subtract 5 hours from the time, though, because the time here is in GMT.  When I try the following, I get an error:

AuctionStartTimeGMT - 5

Microsoft VBScript runtime (0x800A000D)
Type mismatch: '[string: "04:22:50"]'

How do I convert that text string into a time that I can then subtract from to convert this?  Any information would be greatly appreciated.  Thanks!



Avatar of DireOrbAnt
DireOrbAnt

NewDate = DateAdd("h", -5, AuctionStartTimeGMT)
Avatar of Andrew Angell

ASKER

Somehow that's bringing back something crazy for a date...even though I'm doing it to the time variable..???  Here's what I've got now...

AuctionStartGMT = "2006-07-23T04:22:50.776Z"
AuctionStartDate = (Left(AuctionStartGMT,10))
AuctionStartDateSplit = Split(AuctionStartDate, "-")
AuctionStartMo = AuctionStartDateSplit(1)
AuctionStartDay = AuctionStartDateSplit(2)
AuctionStartYear = AuctionStartDateSplit(0)
AuctionStartDate = AuctionStartMo&"/"&AuctionStartDay&"/"&AuctionStartYear
AuctionStartTimeGMT = Mid(AuctionStartGMT,12,8)
AuctionStartTimeGMT = DateAdd("h", -5, AuctionStartTimeGMT)
AuctionStartTimestamp = AuctionStartDate&" "&AuctionStartTimeGMT

response.Write(AuctionStartTimeStamp)

And I'm getting:

07/23/2006 12/29/1899 11:22:50 PM

So it added 5 hours to the time like it should but it also included a crazy date..??
I mean, subtracted 5 hours....
AuctionStartGMT = "2006-07-23T04:22:50.776Z"
AuctionStartTimeGMT = CDate(LEFT(REPLACE(AuctionStartGMT, "T", ""), LEN(AuctionStartGMT)-1))
AuctionStartTimeGMT = DateAdd("h", -5, AuctionStartTimeGMT)

Does that work?
ASKER CERTIFIED SOLUTION
Avatar of DireOrbAnt
DireOrbAnt

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
That seems to have done it.  Thanks!