Powered by GeSHi

Source code for sortdate.pl

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

  1. #! perl
  2.  
  3. # SortDate.pl,  Version 1.00
  4. # Display "sorted" date (YYYYMMDD)
  5. # Written by Rob van der Woude
  6. # http://www.robvanderwoude.com
  7.  
  8. # Parse time string
  9. ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
  10.  
  11. # Add "base year"
  12. $year = $year + 1900;
  13.  
  14. # Add 1, since moth seems to be zero based
  15. $mon  = $mon  + 1;
  16.  
  17. # Add leading zeroes if necessary
  18. if ($mon < 10) {
  19. 	$mon = "0".$mon
  20. }
  21. if ($mday < 10) {
  22. 	$mday = "0".$mday
  23. }
  24.  
  25. # Concatenate substrings
  26. $sortdate = $year.$mon.$mday;
  27.  
  28. # Display result
  29. print "\nSortDate = $sortdate\n";
  30.