Solved

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

Posted on 2016-10-27
3
35 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 52

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 51

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

738 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