Converting Time and Date to a More Useful Format
FANUC and FANUC-compatible CNCs have multiple ways to monitor time. They are accessed by four system variables: milliseconds clock, hours clock, current date and current time. Here’s how to format information in a helpful way.
Share





- Milliseconds clock: (#3001). This variable always runs, can be reset using #3001=0 and will automatically reset after a few minutes (or when the power is turned off).
- Hours clock: (#3002). This variable includes the decimal portion of an hour. It always runs, can be reset using #3002=0, is retained after the power is turned off and will automatically reset after about 397 days.
- Current date: (#3011). This variable is shown in yyyymmdd format. It always runs and cannot be reset.
- Current time: (#3012). This variable is shown in hhmmss, 24-hour format. It always runs and cannot be reset.
The milliseconds clock reset interval is usually too short for any meaningful purpose. The hours clock is much better, but it does not consider “machine off” time. The date and time clocks are great, but their format is somewhat cumbersome. For example, at 3:45:10 p.m. May 3, 2019, we give these commands:
- #101=#3011
- #102=#3012
The values of common variables #101 and #102 will be:
- #101: 20190503 (date)
- #102: 154510 (time)
While this is great information, the format in its current state is not very helpful for timing purposes. They would not help much if, in a program, you need to determine the total amount of time a machine has been in use.
Our upcoming program uses date/time information to parse out the year value, determine the number of hours from the beginning of 2019 (midnight 12/31 of 2018), and the day-number of the current year (from 1 to 365 or 366 in a leap year). Here is the calling command, which could be placed in any program that requires timing an event:
- G65 P9060 D#3011 T#3012 Y102.0 H103.0 F104.0
Where:
- P9060: Program number for custom macro
- D (#7): The date value to convert
- T (#20): The time value to convert
- Y (#25): If included, the number of the variable that will contain the year value.
- H (#11): If included, the number of the variable that will contain the hour value.
- F (#9): If included, the number of the variable that will contain the day number.
If this command is given at 2:25 p.m. on February 4, 2019, the values of #102-#104 will be:
- #102: 2019.0000 (year)
- #103: 834.4146 (hours from the beginning of 2019)
- #104: 35.0000 (days into the year)
Of primary importance is the hours value. It works much like the hours clock, but it is not affected by power on/off status, it considers leap years and it never resets. If the need arises, you could easily modify the program to have it output other time-related information such as month, day or hour.
Example: Need for Warmup
You need to determine elapsed time since finishing the last cycle. If it is over a given amount (say 10-minutes), the machine has cooled and needs to run a warm-up routine. The longer the elapsed time, the longer the required warmup.
Add this command at the end of your machining program:
- G65 P9060 D#3011 T#3012 H500.0
- M30
We only need the current hour, so only the H argument is specified. Now, modify the program’s beginning:
- O0001
- G65 P9060 D#3011 T#3012 H501.0
Next subtract #501 from #500. If the result is greater than 10 minutes (10/60 hours, or 0.1666) a warmup is required:
- #1=#501=#500 (elapsed time)
- IF[#1LE0.16666]GOTO10
- IF[#1LE0.33332] THEN #2=300 (5-minutes)
- IF[[#1GT0.33332] AND [#1LE0.5]] THEN #2=600
- IF[#1GT0.5] THEN #2=900
- S2000 M03 (Start spindle to warmup the headstock)
- G04 X#2 (dwell)
- N10 (Continue)
You may be thinking this easily could have been done with the hours timer (#3002). Keep in mind that the hours timer will ignore any elapsed time that occurs in the power-off state. If this program is run at the beginning of the day/shift, it is likely that the power will have just been turned on. A very long time may have elapsed since the last cycle was run. Since we are using permanent common variables in which to store hours data, elapsed time will be retained after the power is turned off.
Related Content
CNC-Related Features of Custom Macro
CNC-related features of custom macro are separated into two topics: system variables and user-defined G and M codes. This column explores both.
Read More6 Ways to Streamline the Setup Process
The primary goal of a setup reduction program must be to keep setup people working at the machine during the entire setup process.
Read MoreObscure CNC Features That Can Help (or Hurt) You
You cannot begin to take advantage of an available feature if you do not know it exists. Conversely, you will not know how to avoid CNC features that may be detrimental to your process.
Read MoreHow to Determine the Currently Active Work Offset Number
Determining the currently active work offset number is practical when the program zero point is changing between workpieces in a production run.
Read MoreRead Next
AMRs Are Moving Into Manufacturing: 4 Considerations for Implementation
AMRs can provide a flexible, easy-to-use automation platform so long as manufacturers choose a suitable task and prepare their facilities.
Read MoreMachine Shop MBA
Making Chips and 91ÊÓÆµÍøÕ¾ÎÛ are teaming up for a new podcast series called Machine Shop MBA—designed to help manufacturers measure their success against the industry’s best. Through the lens of the Top Shops benchmarking program, the series explores the KPIs that set high-performing shops apart, from machine utilization and first-pass yield to employee engagement and revenue per employee.
Read More