Convert time

• Time will often be stored as YYYYMMDD, or a similar format, in a computer database or file.  To convert to a useful format, with 20150117 as an example:
• Divide by 10000 and truncate: Year = trunc(20150117 / 10000) = 2015.  If the language does not support trunc, it might call it "floor".  This rounds down.
• Get the remainder: temp=20150117 -10000 * Year; temp will be 117 (note you lose the leading 0).
• Get the month with an appropriate division.
• Get the remainder, which will be the day.
• Putting it back into a decimal year is tricky because the months have different lengths (you can use Julian days, and should see if Excel or Matlab has functions to help).  If you had instead broken up time in hr, min, and sec, the decimal hours will be hours=hr + min/60 + sec/3600.
• If you use the data import wizard, you can also break the input into three fields by manually setting the divisions.  You can also use the text to columns option.
• This same operation can be done with HHMMSS.

last revision 1/11/2017