Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for yesterday.pl

(view source code of yesterday.pl as plain text)

  1. #! perl
  2.  
  3. # Yesterday.pl,  Version 1.00
  4. # Display yesterday's "sorted" date (YYYYMMDD)
  5. # Written by Rob van der Woude
  6. # http://www.robvanderwoude.com
  7.  
  8. # Specify function library
  9. use Time::Local;
  10.  
  11. # Convert today to epoch seconds
  12. $today = timelocal(localtime);
  13.  
  14. # Subtract 1 day
  15. @yesterday = localtime($today - (24 * 60 * 60));
  16.  
  17. # Extract year, month and day, and correct base offsets
  18. $year  = (@yesterday)[5] + 1900;
  19. $month = (@yesterday)[4] + 1;
  20. $day   = (@yesterday)[3];
  21.  
  22. # Display the result, correctly formated
  23. printf("\nYesterday = %04d%02d%02d\n", $year, $month, $day);
  24.  

page last modified: 2024-04-16; loaded in 0.0061 seconds