Converting MS Access Date/Time

MarkTTU

Lifetime Supporting Member
Join Date
Jun 2004
Location
Lago Vista, Texas
Posts
646
I've got an application where a date/time stamp stored in a database needs to be pulled from the database and displayed on a C-More. I've got the function working to pull the number from the database into a DL06, but I'm not real sure how to handle the number I get back from the database because Microsoft stores date/time stamps as a real number with 1/1/1900 being 1 and counting each day from there; fractions of days are hours, minutes, seconds... From the Access help file:
----------------------------
About dates and date systems
Microsoft Access stores dates as sequential numbers which are called serial values. By default, January 1, 1900 is serial number 1, and January 1, 2008 is serial number 39448 because it is 39,448 days after January 1, 1900. Access stores times as decimal fractions because time is considered a portion of a day.
--------------------------------------

OK so given all that does anyone have any ideas on how to convert this number back into a intelligible date and time I can display on the C-More?

Thanks.
 
Well,
The Time portion is very easy. Take the decimal portion of the number. Take 10000.78 for example. Extract the .78 and multiply it by 24(hours), this will give you 18.72. 18 will be your hour. Take the .72 and multiply it by 60(minutes), this gives you 43.2. 43 will be your minutes. Take the .2 and multiply by 60(seconds) and this gives you 12. Combine the three results to get your time of day. 18:43:12.
The Day,Month,Year on the other hand is tricky. I would start by searching on google for Leap Year Calculations, that will be the toughest part. Once you figured out the year, you could start subtracting in order of months like -31 for Jan, -28 for Feb and so on until you your value was less than a whole number of days in a month. then take that remainder as the day in that month.
 
I think you're on to something there; I'll look around and see if I can find anything on how to calculate which years are leap years...
 
If it's divisible by 4, and isn't a century (1900/2000/2100) it's a leap year. If it's a century, and divisible by 400 (1600/2000/2400) it's a leap year.
 
I would not store the whole date value in the dl-06. I would break the date into three separate values (day, month, and year) on the pc end and store these three values in the dl-06.
 
Hello Ben,
I don't know if this will help but, using the format function in Access will return a string variant. The format function is very flexible in terms of display a date/time field.

-William
 

Similar Topics

Hello everyone, can anyone help me with covert the STL code to ladder. Iam using plc s71200. A %DB1.DBX33.7 // angel of vaccum...
Replies
2
Views
198
Hello PLCs Forum, I am in a bit of a pickle and was hoping someone could offer me some help. I have a .rss file and just need to see the ladder...
Replies
2
Views
113
Hello nice to meet you, im new in here, I'm currently trying to convert code written in STL for a S7-400 to SCL for an S7-1500, because when i run...
Replies
5
Views
292
Hello, did anybody know, if there exist an converting cable like the1492-CM1746-M01 (for an 1746-IB16 to an 5069-IB16), for an 1746-HSCE to an...
Replies
3
Views
381
Hello, This will be my first time converting powerflex 40's and 400's from devicenet to ethernet. I did some research, and it seems I will need...
Replies
4
Views
726
Back
Top Bottom