Print Yesterday’s Date Using Perl

| 22 Dec 2006 | Posts | 6,693 views

Quick tip for working with Unix scripts that need yesterday’s date. If you have Perl, try this:

perl -e ‘@y=localtime(time()-86400);printf “%04d%02d%02d”,$y[5]+1900,$y[4]+1,$y[3];’

should print to stdout the date in the yyyymmdd format. Much simpler than writing an entire function in a script and messing around with 1st of the month, leap years, and possibly dates beyond 2037 (check Perl documentation).

Links:

The UNIX Forums – get yesterday in yyyymmdd format
http://www.unix.com/showthread.php?t=20181>

Technorati Tags: , , , ,

Share

Related posts:

:, , Subscribe


2 Comments for this entry

Leave a Reply

Archives

Be Good

View Teng-Yan Loke's profile on LinkedIn

The Hunger Site

Counter visits since 16 Sep 2006

Technology Blogs - BlogCatalog Blog Directory