Help! A good computer math question

Keystone

Lifetime Supporting Member
Join Date
Aug 2008
Location
Indiana
Posts
130
I need to convert ControlLogix UTC time (milli-sec from 1970) to "standard" DATETIME format to send to my date base.

EXAMPLE (In DATETIME format 39993.4976972222=
"6/29/2009 11:56:41 AM ")

So how does UTC (1246291051356831) relate to
39993.4976972222 to equal "6/29/2009 11:56:41 AM "
the same Date and Time.

I need to gather the start time in my PLC because it is the start of a process and I need to log start time and length of process along with process data.

If anyone has an idea please let me know.

Thanks
 
I think you should use a GSV wallclocktime with the attribute LocalDateTime to let the CPU do the conversion for you. Use a DINT array with 7 elements as the destination.

Then you should end up with:
Dint[0]=year
Dint[1]=month
Dint[2]=day
Dint[3]=hour
Dint[4]=minute
Dint[5]=second
Dint[6]=microsecond

Paul
 
Why not use the GSV (Get System Value)called "WallClockTime".

The PLC will figure it all out for you.

Just create a Dint[7] to send the data to.

Look at rung 0 of this PDF for an example. (Page 3 shows the tags)
 
OkiePC & TheStarr

Thanks for your reply. I know that I can get Year, Day, Hour, Min, Sec, etc. I am already using a GSV to get WallClockClock - CurrentValue as a LINT. What I was looking for was a time stamp value that I can send to my data base in a MS standard DATETIME format. This way if I need to retrieve the information the IT people can do a standard search in a DATETIME field.

It does not sound much different than your solution but it is a bit difference to my IT dept.
 
Could you give an actual example of what you want to output? Would each value (day, month, year, etc) be in it's own column? What kind of database is it? (DDE, OPC, SQL, etc....)
 
Let's note that the DATETIME is probably the Excel version which is "days since 1/1/1900"."fractional part of the day".

A couple good numbers would be 25569 (days from 1/1/1900 to 1/1/1970) and 86400000 (number of miliseconds in a day).

If you can get the integer portion of the division of UTC by 86400000 and add 25569 you should have the integer portion of the DATETIME.

If you can get the remainder from the above division and divide it by 86400000 then that should give you the fractional part of the DATETIME.

Now whether these two numbers can be combined into a float that has any degree of precision is a problem.
 
You don't have to send it in raw format to a database, send it structured '01/21/2009 15:53', and the database will handle the conversion to it's raw format. I'm assuming you are using SQL server here, since you specified the MS DATETIME format.
 

Similar Topics

I have a Micro820 here that will eventually be used as a slave device and will have information pulled from it serially. I need to test the...
Replies
14
Views
4,470
A client of mine has asked for assistance. They have a Jenbacher generator which uses a B&R 2003 plc. This appears to communicate with a B&R...
Replies
3
Views
5,529
Hi, Thanks to everyone for help on my last post. I have gone ahead and ordered the Automation Direct PLC's that I need and I am quite impressed...
Replies
9
Views
2,526
Hi, all. I just got an Omron CPM2A off eBay and I need to make my own serial cable to connect it to my computer for programming. I will be...
Replies
5
Views
12,335
Could someone help me with computer link protocol from mitsubishi? I need to transmitt data to a FX2N plc. For this I developed a program in java...
Replies
2
Views
4,688
Back
Top Bottom