Solved

How to change value of hours and seconds in the same date string?

Posted on 2016-10-27
3
19 Views
Last Modified: 2016-10-28
I have a vba dateString variable in "longTime format" that is uncorrected for daylight saving,
I must adjust the hours value by -1, and then I need to adjust the seconds value by -1

Dim strDate As String
Dim dtDate As Date

The model of my string date:
      strDate = Format(Time, "Log Time")n
I can change the hour parameter in that date
      dtDate = DateAdd("h", -1, strDate)
or the second parameter
      dtDate = DateAdd("s", -1, strDate)

But how do I change BOTH parameters in the same date?
    ("s", -1, strDate) and ("h", -1, strDate)

Thanks
Kelvin
0
Comment
Question by:Kelvin4
3 Comments
 
LVL 49

Accepted Solution

by:
Ryan Chong earned 250 total points
ID: 41863444
try this:
dtDate = DateAdd("h", -1, strDate)
    dtDate = DateAdd("s", -1, dtDate)

Open in new window

or
dtDate  = DateAdd("s", -1, DateAdd("h", -1, Format(Time, "Long Time")))

Open in new window

or
dtDate  = DateAdd("s", -1, DateAdd("h", -1, strDate))

Open in new window

0
 
LVL 48

Assisted Solution

by:Rgonzo1971
Rgonzo1971 earned 250 total points
ID: 41863446
Hi,

pls try

dtDate = DateAdd("s", -3601, strDate)

Open in new window

3600s = 1h

Regards
0
 

Author Closing Comment

by:Kelvin4
ID: 41863459
Thanks to both. I should have used my head - twice!!
Kelvin
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Modern/Metro styled message box and input box that directly can replace MsgBox() and InputBox()in Microsoft Access 2013 and later. Also included is a preconfigured error box to be used in error handling.
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now