Christopher Juckins

SysAdmin Tips, Tricks and other Software Tools

User Tools

Site Tools


manipulating_date_strings

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revisionBoth sides next revision
manipulating_date_strings [2011/11/20 10:48] juckinsmanipulating_date_strings [2012/01/03 21:47] juckins
Line 16: Line 16:
 [cjuckins@lnxopc2: ~]$ zdump America/Los_Angeles [cjuckins@lnxopc2: ~]$ zdump America/Los_Angeles
 America/Los_Angeles  Tue May  3 10:41:52 2011 PDT America/Los_Angeles  Tue May  3 10:41:52 2011 PDT
 +</code>
 +
 +<code>
 +If you take the date/time line from a current text product, such as:
 +
 +806 PM EST TUE 3 JAN 2012
 +
 +Add a colon to the hour/minute:
 +
 +8:06 PM EST TUE 3 JAN 2012
 +
 +You can feed that string directly into the linux date command and
 +manipulate it forward and backward by any amount of time and then print
 +it out in the same format.
 +
 +Forward 6 hours:
 +$ date --date="8:06 PM EST TUE 3 JAN 2012 6 hours" "+%I%M %p %Z %a %d %b
 +%Y" | sed 's/^0//' | sed 's/\s0/ /g' | sed 's/./\u&/g'
 +206 AM EST WED 4 JAN 2012
 +
 +Forward 30 minutes:
 +date --date="8:06 PM EST TUE 3 JAN 2012 30 minutes" "+%I%M %p %Z %a %d
 +%b %Y" | sed 's/^0//' | sed 's/\s0/ /g' | sed 's/./\u&/g'
 +836 PM EST TUE 3 JAN 2012
 +
 +Backward 12 hours:
 +date --date="8:06 PM EST TUE 3 JAN 2012 -12 hours" "+%I%M %p %Z %a %d %b
 +%Y" | sed 's/^0//' | sed 's/\s0/ /g' | sed 's/./\u&/g'
 +806 AM EST TUE 3 JAN 2012
 +
 +The 1st sed strips any leading zeros at the beginning of the line, the
 +2nd sed strips any other leading zeros, and the final sed makes it all
 +UPPER.
 </code> </code>
  
manipulating_date_strings.txt · Last modified: 2022/05/07 12:33 by juckins