getdate() with adodb_getdate() date() with adodb_date() gmdate() with adodb_gmdate() mktime() with adodb_mktime() gmmktime() with adodb_gmmktime() strftime() with adodb_strftime() strftime() with adodb_gmstrftime()
a - "am" or "pm" A - "AM" or "PM" d - day of the month, 2 digits with leading zeros; i.e. "01" to "31" D - day of the week, textual, 3 letters; e.g. "Fri" F - month, textual, long; e.g. "January" g - hour, 12-hour format without leading zeros; i.e. "1" to "12" G - hour, 24-hour format without leading zeros; i.e. "0" to "23" h - hour, 12-hour format; i.e. "01" to "12" H - hour, 24-hour format; i.e. "00" to "23" i - minutes; i.e. "00" to "59" j - day of the month without leading zeros; i.e. "1" to "31" l (lowercase 'L') - day of the week, textual, long; e.g. "Friday" L - boolean for whether it is a leap year; i.e. "0" or "1" m - month; i.e. "01" to "12" M - month, textual, 3 letters; e.g. "Jan" n - month without leading zeros; i.e. "1" to "12" O - Difference to Greenwich time in hours; e.g. "+0200" Q - Quarter, as in 1, 2, 3, 4 r - RFC 2822 formatted date; e.g. "Thu, 21 Dec 2000 16:01:07 +0200" s - seconds; i.e. "00" to "59" S - English ordinal suffix for the day of the month, 2 characters; i.e. "st", "nd", "rd" or "th" t - number of days in the given month; i.e. "28" to "31" T - Timezone setting of this machine; e.g. "EST" or "MDT" U - seconds since the Unix Epoch (January 1 1970 00:00:00 GMT) w - day of the week, numeric, i.e. "0" (Sunday) to "6" (Saturday) Y - year, 4 digits; e.g. "1999" y - year, 2 digits; e.g. "99" z - day of the year; i.e. "0" to "365" Z - timezone offset in seconds (i.e. "-43200" to "43200"). The offset for timezones west of UTC is always negative, and for those east of UTC is always positive.
B - Swatch Internet time I (capital i) - "1" if Daylight Savings Time, "0" otherwise. W - ISO-8601 week number of year, weeks starting on Monday
%a - abbreviated weekday name according to the current locale %A - full weekday name according to the current locale %b - abbreviated month name according to the current locale %B - full month name according to the current locale %c - preferred date and time representation for the current locale %d - day of the month as a decimal number (range 01 to 31) %D - same as %m/%d/%y %e - day of the month as a decimal number, a single digit is preceded by a space (range ' 1' to '31') %h - same as %b %H - hour as a decimal number using a 24-hour clock (range 00 to 23) %I - hour as a decimal number using a 12-hour clock (range 01 to 12) %m - month as a decimal number (range 01 to 12) %M - minute as a decimal number %n - newline character %p - either `am' or `pm' according to the given time value, or the corresponding strings for the current locale %r - time in a.m. and p.m. notation %R - time in 24 hour notation %S - second as a decimal number %t - tab character %T - current time, equal to %H:%M:%S %x - preferred date representation for the current locale without the time %X - preferred time representation for the current locale without the date %y - year as a decimal number without a century (range 00 to 99) %Y - year as a decimal number including the century %Z - time zone or name or abbreviation %% - a literal `%' character
%C - century number (the year divided by 100 and truncated to an integer, range 00 to 99) %g - like %G, but without the century. %G - The 4-digit year corresponding to the ISO week number (see %V). This has the same format and value as %Y, except that if the ISO week number belongs to the previous or next year, that year is used instead. %j - day of the year as a decimal number (range 001 to 366) %u - weekday as a decimal number [1,7], with 1 representing Monday %U - week number of the current year as a decimal number, starting with the first Sunday as the first day of the first week %V - The ISO 8601:1988 week number of the current year as a decimal number, range 01 to 53, where week 1 is the first week that has at least 4 days in the current year, and with Monday as the first day of the week. (Use %G or %g for the year component that corresponds to the week number for the specified timestamp.) %w - day of the week as a decimal, Sunday being 0 %W - week number of the current year as a decimal number, starting with the first Monday as the first day of the first week
'; echo 'adodb: ',adodb_date($fmt,$t),''; echo 'php : ',date($fmt,$t),''; echo '
Testing gregorian <=> julian conversion
"; $t = adodb_mktime(0,0,0,10,11,1492); //http://www.holidayorigins.com/html/columbus_day.html - Friday check if (!(adodb_date('D Y-m-d',$t) == 'Fri 1492-10-11')) print 'Error in Columbus landing'; $t = adodb_mktime(0,0,0,2,29,1500); if (!(adodb_date('Y-m-d',$t) == '1500-02-29')) print 'Error in julian leap years'; $t = adodb_mktime(0,0,0,2,29,1700); if (!(adodb_date('Y-m-d',$t) == '1700-03-01')) print 'Error in gregorian leap years'; print adodb_mktime(0,0,0,10,4,1582).' '; print adodb_mktime(0,0,0,10,15,1582); $diff = (adodb_mktime(0,0,0,10,15,1582) - adodb_mktime(0,0,0,10,4,1582)); if ($diff != 3600*24) print " Error in gregorian correction = ".($diff/3600/24)." days "; print " 15 Oct 1582, Fri=".(adodb_dow(1582,10,15) == 5 ? 'Fri' : 'Error').""; print " 4 Oct 1582, Thu=".(adodb_dow(1582,10,4) == 4 ? 'Thu' : 'Error').""; print "
Testing overflow
"; $t = adodb_mktime(0,0,0,3,33,1965); if (!(adodb_date('Y-m-d',$t) == '1965-04-02')) print 'Error in day overflow 1 '; $t = adodb_mktime(0,0,0,4,33,1971); if (!(adodb_date('Y-m-d',$t) == '1971-05-03')) print 'Error in day overflow 2 '; $t = adodb_mktime(0,0,0,1,60,1965); if (!(adodb_date('Y-m-d',$t) == '1965-03-01')) print 'Error in day overflow 3 '.adodb_date('Y-m-d',$t).' '; $t = adodb_mktime(0,0,0,12,32,1965); if (!(adodb_date('Y-m-d',$t) == '1966-01-01')) print 'Error in day overflow 4 '.adodb_date('Y-m-d',$t).' '; $t = adodb_mktime(0,0,0,12,63,1965); if (!(adodb_date('Y-m-d',$t) == '1966-02-01')) print 'Error in day overflow 5 '.adodb_date('Y-m-d',$t).' '; $t = adodb_mktime(0,0,0,13,3,1965); if (!(adodb_date('Y-m-d',$t) == '1966-01-03')) print 'Error in mth overflow 1 '; print "Testing 2-digit => 4-digit year conversion
"; if (adodb_year_digit_check(00) != 2000) print "Err 2-digit 2000"; if (adodb_year_digit_check(10) != 2010) print "Err 2-digit 2010"; if (adodb_year_digit_check(20) != 2020) print "Err 2-digit 2020"; if (adodb_year_digit_check(30) != 2030) print "Err 2-digit 2030"; if (adodb_year_digit_check(40) != 1940) print "Err 2-digit 1940"; if (adodb_year_digit_check(50) != 1950) print "Err 2-digit 1950"; if (adodb_year_digit_check(90) != 1990) print "Err 2-digit 1990"; // Test string formating print "
Testing date formating
"; $pos = strcmp($s1,$s2); if (($s1) != ($s2)) { for ($j=0,$k=strlen($s1); $j < $k; $j++) { if ($s1[$j] != $s2[$j]) { print substr($s1,$j).' '; break; } } print "Error date(): $ts \"$s1\" (date len=".strlen($s1).") \"$s2\" (adodb_date len=".strlen($s2).")"; $fail = true; } $a1 = getdate($ts); $a2 = adodb_getdate($ts); $rez = array_diff($a1,$a2); if (sizeof($rez)>0) { print "Error getdate() $ts"; print_r($a1); print ""; print_r($a2); print "
\"$s1\" (date len=".strlen($s1).") \"$s2\" (adodb_date len=".strlen($s2).")
"; $fail = true; } } // Test generation of dates outside 1901-2038 print "
Testing random dates between 100 and 4000
'; $start = 1960+rand(0,10); $yrs = 12; $i = 365.25*86400*($start-1970); $offset = 36000+rand(10000,60000); $max = 365*$yrs*86400; $lastyear = 0; // we generate a timestamp, convert it to a date, and convert it back to a timestamp // and check if the roundtrip broke the original timestamp value. print "Testing $start to ".($start+$yrs).", or $max seconds, offset=$offset: "; $cnt = 0; for ($max += $i; $i < $max; $i += $offset) { $ret = adodb_date('m,d,Y,H,i,s',$i); $arr = explode(',',$ret); if ($lastyear != $arr[2]) { $lastyear = $arr[2]; print " $lastyear "; flush(); } $newi = adodb_mktime($arr[3],$arr[4],$arr[5],$arr[0],$arr[1],$arr[2]); if ($i != $newi) { print "Error at $i, adodb_mktime returned $newi ($ret)"; $fail = true; break; } $cnt += 1; } echo "Tested $cnt dates"; if (!$fail) print "
Passed !
Failed :-(