get century from date-time

Get 2-digit century from given date (i.e. time in epoch seconds). For example, the century for 1999 is '19'.

Download getcenturyfromdate.zip

Synopsis:

getcenturyfromdate.pl


getcenturyfromdate.pl

Synopsis
sub GetCenturyFromDate($)
  {
  my ($t) = @_;
  return int(((localtime shift)[5] + 1900) / 100);
  }

#-- unit tests
sub test_getcenturyfromdate()
  {
  ut::assert(GetCenturyFromDate(0), 19);
  ut::assert(GetCenturyFromDate(28799), 19);
  ut::assert(GetCenturyFromDate(28800), 19);  #28800 seconds is 8 hours
  ut::assert(GetCenturyFromDate(1056523422), 20);
  ut::assert(GetCenturyFromDate(1096523422), 20);
  }

1;






Contact me about content on this page using john_web-at-arrizza-dot-com
For Web Master or site problems contact: webadmin-at-arrizza-dot-com
Copyright John Arrizza (c) 2001,2002,2003,2004,2005,2006,2007