PC Review


Reply
Thread Tools Rate Thread

Convert Date/Time in VBA

 
 
kidkosmo
Guest
Posts: n/a
 
      28th Apr 2009
Hi, All,

I am pulling data from a data source in which the format is the Long
Date format (i.e. "1/1/09 12:00:00 AM") and inserting it into another
table. The original data source as the time for the GMT timezone and
I want to convert that to EST timezone (i.e. 1/1/09 12:01:00 AM
becomes 12/31/2008 7:01:00 PM). Here's how I have my SQL statement
created:

strsql2 = "INSERT INTO TestTheory (OPEN_TIME, OpenDate, OpenTime)
VALUES ('" & _
rst!OPEN_TIME & _
strSep & _
Format$(rst!OPEN_TIME, "Short Date") & _
strSep & _
Format$(rst!OPEN_TIME, "Short Time") & _

How can I quickly recalculate rst!OPEN_TIME to subtract 5 hours so
that I get the correct Eastern timezone date and time when I reformat
for the additional columns?

Thanks!!!
 
Reply With Quote
 
 
 
 
Douglas J. Steele
Guest
Posts: n/a
 
      28th Apr 2009
You really should be storing date and time in a single field. That's the way
the Date data type was designed in Access: it's an eight-byte floating point
number where the integer portion represents the date as the number of days
relative to 30 Dec, 1899 and the decimal portion represents the time as a
fraction of a day. When you only store a date, you're actually storing that
date at midnight. When you only store a time, you're actually storing that
time on 30 Dec, 1899.

Should you have occasion where you only need the date portion, or you only
need the time portion, you can use the DateValue or TimeValue functions.

In any case, the answer to your specific question is the DateAdd function:

DateAdd("h", -5, rst!OPEN_TIME)



--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)


"kidkosmo" <(E-Mail Removed)> wrote in message
news:0ccfc1ad-340c-4dfa-9e79-(E-Mail Removed)...
> Hi, All,
>
> I am pulling data from a data source in which the format is the Long
> Date format (i.e. "1/1/09 12:00:00 AM") and inserting it into another
> table. The original data source as the time for the GMT timezone and
> I want to convert that to EST timezone (i.e. 1/1/09 12:01:00 AM
> becomes 12/31/2008 7:01:00 PM). Here's how I have my SQL statement
> created:
>
> strsql2 = "INSERT INTO TestTheory (OPEN_TIME, OpenDate, OpenTime)
> VALUES ('" & _
> rst!OPEN_TIME & _
> strSep & _
> Format$(rst!OPEN_TIME, "Short Date") & _
> strSep & _
> Format$(rst!OPEN_TIME, "Short Time") & _
>
> How can I quickly recalculate rst!OPEN_TIME to subtract 5 hours so
> that I get the correct Eastern timezone date and time when I reformat
> for the additional columns?
>
> Thanks!!!



 
Reply With Quote
 
John W. Vinson
Guest
Posts: n/a
 
      28th Apr 2009
On Tue, 28 Apr 2009 12:10:48 -0700 (PDT), kidkosmo <(E-Mail Removed)>
wrote:

>Hi, All,
>
>I am pulling data from a data source in which the format is the Long
>Date format (i.e. "1/1/09 12:00:00 AM") and inserting it into another
>table. The original data source as the time for the GMT timezone and
>I want to convert that to EST timezone (i.e. 1/1/09 12:01:00 AM
>becomes 12/31/2008 7:01:00 PM). Here's how I have my SQL statement
>created:
>
>strsql2 = "INSERT INTO TestTheory (OPEN_TIME, OpenDate, OpenTime)
>VALUES ('" & _
> rst!OPEN_TIME & _
> strSep & _
> Format$(rst!OPEN_TIME, "Short Date") & _
> strSep & _
> Format$(rst!OPEN_TIME, "Short Time") & _
>
>How can I quickly recalculate rst!OPEN_TIME to subtract 5 hours so
>that I get the correct Eastern timezone date and time when I reformat
>for the additional columns?
>
>Thanks!!!


First off... splitting a date/time value into separate date and time fields is
just going to give you problems. You'll need to convert them or combine them
later for searching and reporting.

An Access Date/Time value, regardless of format, is stored as a Double Float
count of days and fractions of a day (times) since midnight, December 30,
1899. The format is not stored in the data, it just controls how the data is
displayed. You can use an expression like

DateAdd("h", 5, [OPEN_TIME])

to calculate the EST time, either in your append query or in an Update query.
Accounting for daylight savings time makes life a bit more complex!
--

John W. Vinson [MVP]
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Convert unix time to date/time in Access 2003 for a linked tabel Kevin Joyce Microsoft Access Getting Started 5 7th Oct 2008 08:18 PM
Convert from Unix time to Access Date/Time? Marty Christion Microsoft Access 3 11th May 2006 06:41 PM
How do I convert a date&time (yyyy-mm-dd hh:mm:ss) to date only? =?Utf-8?B?V2VzbGV5IEFjY2VsbGVudA==?= Microsoft Excel Worksheet Functions 7 1st Dec 2005 07:59 PM
Convert date to length of time in months from set date =?Utf-8?B?TUpVSw==?= Microsoft Excel Worksheet Functions 1 19th Mar 2005 06:31 PM
Convert Date Time in Spreadsheet Column to Date only Genga Microsoft Excel Programming 1 8th Jun 2004 08:18 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:44 AM.