Date time format from plc

briana banks

Member
Join Date
Jul 2005
Posts
242
Hi All

Using RSlogix 5000.
Can anyone show me a code snippet that takes the plc time & date
and convert it to string format?

Thanks
 
I remembered having used somthing called concatenate in order to assemple a string. In this case you have to use your S2 registers. After assembling the string you can send a message.
 
Taka a look at KB 1756-EWEB socket samlple code 32962

It has soubroutine that does time conversion to string
 
Here is a ST routine that builds a Date and time string, as in

Feb 26, 2007, 4:09:00 P.M.

Code:
//Creates a date time string in the form  MMMM DD, YYYY, HH:MM:SS A.M.
//sSTR is a string tag
//StringConst is a String[18] array.
//StringConst[0] = "0"
//StringConst[1] = "Jan. "
//StringConst[2] = "Feb. "
//StringConst[3] = "Mar. "
//StringConst[4] = "Apr. "
//StringConst[5] = " May "
//StringConst[6] = "June "
//StringConst[7] = "July "
//StringConst[8] = "Aug. "
//StringConst[9] = "Sep. "
//StringConst[10] = "Oct. "
//StringConst[11] = "Nov. "
//StringConst[12] = "Dec. "
//StringConst[13] = "."
//StringConst[14] = " "
//StringConst[15] = ":"
//StringConst[16] = "A.M."
//StringConst[17] = "P.M."
//sPtr is a DINT
//CurrentWallClock[0] = year
//CurrentWallClock[1] = month
//CurrentWallClock[2] = day
//CurrentWallClock[3] = Hour
//CurrentWallClock[4] = Minute
//CurrentWallClock[5] = Second
GSV(WallClockTime,,DateTime,CurrentWallClock[0]);  //Get the time from the system.
DTOS(CurrentWallClock[2], sSTR);				  //convert the current day to a string.
IF CurrentWallClock[2]<10 Then					//append leading zero if day is less than 10
 Concat(StringConst[0],sSTR, sSTR); 
End_if;
dPtr:=CurrentWallClock[1];						//set pointer to month to point to string constants array for month name
CONCAT (StringConst[dPtr], sSTR, sDateTime);	  //Put together the month name with the date
CONCAT (sDateTime, StringConst[13], sDateTime);   //Add a comma
CONCAT (sDateTime, StringConst[14], sDateTime);   //Add a space
DTOS(CurrentWallClock[0], sSTR);				  //convert the year to a string
CONCAT (sDateTime, sSTR, sDateTime);			  //add in the year
CONCAT (sDateTime, StringConst[13], sDateTime);   //Add a comma
CONCAT (sDateTime, StringConst[14], sDateTime);   //Add a space
IF CurrentWallClock[3] > 12 Then				  //Adjust hour for P.M.
 dPtr := CurrentWallClock[3] - 12;
Else
 dPtr := CurrentWallClock[3];
End_if;
If dPtr < 10 Then 
 ConCat(sDateTime, StringConst[0], sDateTime); //add a leading zero for single digit hours
End_If;
DTOS(dPtr, sSTR);								 //convert hours to a string
CONCAT(sDateTime, sSTR, sDateTime);			   //add hours string to date time string;
CONCAT(sDateTime, StringConst[15], sDateTime);	//Add a colon
If CurrentWallClock[4]<10 Then					//Append a 0 if minutes is less than 10
 Concat(sDateTime, StringConst[0], sDateTime);
End_if;
DTOS(CurrentWallClock[4], sSTR);				  //convert minutes to a string
CONCAT(sDateTime, sSTR, sDateTime);			   //append minutes to date time string.
CONCAT(sDateTime, StringConst[15], sDateTime);	//Add a colon
If CurrentWallClock[5]<10 Then					//Append a 0 if seconds is less than 10
 Concat(sDateTime, StringConst[0], sDateTime);
End_if;
DTOS(CurrentWallClock[5], sSTR);				  //convert seconds to a string
CONCAT(sDateTime, sSTR, sDateTime);			   //append seconds to date time string
CONCAT (sDateTime, StringConst[14], sDateTime);   //Add a space
If CurrentWallClock[2] > 12 Then				  // add in P.M. or A.M.
 CONCAT(sDateTime, StringConst[17], sDateTime);
ELSE
 CONCAT(sDateTime, StringConst[16], sDateTime);
End_IF;
 
Last edited:

Similar Topics

Hello: I have an Siemens S7 PLC appliaction and a module CP340 for seial communication with Hyperterminal. I've got to format a ASCII string that...
Replies
2
Views
8,671
I can't see any option to display the date in UK format, i.e. dd/mm/yyyy Is it available in TIA Portal v18?
Replies
21
Views
1,787
Have several hmi screens mirrored to different Nematron Screens using Thin manager , need to have the clocks synced and 24 hour format , My screen...
Replies
2
Views
2,762
Hi all, I'm using Siemens TIA Portal V13 SP1 Update 7 and I'm configuring a TP1200 Comfort Panel HMI. I'm trying to display the date and time...
Replies
1
Views
12,342
I am working on a project for an international client and they requested I put the date in the alarm log in DD-MM-YYYY instead of the MM-DD-YYYY I...
Replies
2
Views
1,843
Back
Top Bottom