?
Solved

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

Posted on 2016-10-27
3
Medium Priority
?
43 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 53

Accepted Solution

by:
Ryan Chong earned 1000 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 52

Assisted Solution

by:Rgonzo1971
Rgonzo1971 earned 1000 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

Want to be a Web Developer? Get Certified Today!

Enroll in the Certified Web Development Professional course package to learn HTML, Javascript, and PHP. Build a solid foundation to work toward your dream job!

Question has a verified solution.

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

Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
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…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

771 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