PHP  
downloads | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | my php.net 
search for in the  
<bzwritecal_days_in_month>
view the version of this page
Last updated: Thu, 21 Aug 2003

VI. Calendar functions

Introduction

The calendar extension presents a series of functions to simplify converting between different calendar formats. The intermediary or standard it is based on is the Julian Day Count. The Julian Day Count is a count of days starting from January 1st, 4713 B.C. To convert between calendar systems, you must first convert to Julian Day Count, then to the calendar system of your choice. Julian Day Count is very different from the Julian Calendar! For more information on Julian Day Count, visit http://www.hermetic.ch/cal_stud/jdn.htm. For more information on calendar systems visit http://www.boogle.com/info/cal-overview.html. Excerpts from this page are included in these instructions, and are in quotes.

Installation

To get these functions to work, you have to compile PHP with --enable-calendar.

The windows version of PHP has built in support for this extension. You do not need to load any additional extension in order to use these functions.

Runtime Configuration

This extension has no configuration directives defined in php.ini.

Resource Types

This extension has no resource types defined.

Predefined Constants

The constants below are defined by this extension, and will only be available when the extension has either been compiled into PHP or dynamically loaded at runtime.

CAL_GREGORIAN (integer)

CAL_JULIAN (integer)

CAL_JEWISH (integer)

CAL_FRENCH (integer)

CAL_NUM_CALS (integer)

CAL_DOW_DAYNO (integer)

CAL_DOW_SHORT (integer)

CAL_DOW_LONG (integer)

CAL_MONTH_GREGORIAN_SHORT (integer)

CAL_MONTH_GREGORIAN_LONG (integer)

CAL_MONTH_JULIAN_SHORT (integer)

CAL_MONTH_JULIAN_LONG (integer)

CAL_MONTH_JEWISH (integer)

CAL_MONTH_FRENCH (integer)

The following constants are available since PHP 4.3.0 :

CAL_EASTER_DEFAULT (integer)

CAL_EASTER_ROMAN (integer)

CAL_EASTER_ALWAYS_GREGORIAN (integer)

CAL_EASTER_ALWAYS_JULIAN (integer)

The following constants are available since PHP 5.0.0 :

CAL_JEWISH_ADD_ALAFIM_GERESH (integer)

CAL_JEWISH_ADD_ALAFIM (integer)

CAL_JEWISH_ADD_GERESHAYIM (integer)

Table of Contents
cal_days_in_month -- Return the number of days in a month for a given year and calendar
cal_from_jd -- Converts from Julian Day Count to a supported calendar
cal_info -- Returns information about a particular calendar
cal_to_jd -- Converts from a supported calendar to Julian Day Count
easter_date --  Get UNIX timestamp for midnight on Easter of a given year
easter_days --  Get number of days after March 21 on which Easter falls for a given year
FrenchToJD --  Converts a date from the French Republican Calendar to a Julian Day Count
GregorianToJD --  Converts a Gregorian date to Julian Day Count
JDDayOfWeek -- Returns the day of the week
JDMonthName -- Returns a month name
JDToFrench --  Converts a Julian Day Count to the French Republican Calendar
JDToGregorian -- Converts Julian Day Count to Gregorian date
jdtojewish --  Converts a julian day count to a jewish calendar date
JDToJulian --  Converts a Julian Day Count to a Julian Calendar Date
jdtounix -- Convert Julian Day to UNIX timestamp
JewishToJD --  Converts a date in the Jewish Calendar to Julian Day Count
JulianToJD --  Converts a Julian Calendar date to Julian Day Count
unixtojd -- Convert UNIX timestamp to Julian Day


add a note add a note User Contributed Notes
Calendar functions
jthome at fcgov dot com
03-Oct-2003 01:38
Had a similar problem as curlee, except I needed to create a JDE_ERP date.  [format is CYYDDD]

<?php

function jde_date_create($month$day$year){
   
/*
    *  NOTE: $month and $day CANNOT have leading zeroes,
    *        $year must be'YYYY' format
    */
   
$jde_year_prefix substr($year01) - 1;
   
$jde_year_suffix substr($year, -2);
   
   
//note that valid years for mktime are 1902-2037
   
$timestamp mktime(0,0,0,$month$day$year);
   
$baseline_timestamp mktime(0,0,0,1,0,$year);
   
   
$day_count round(($timestamp $baseline_timestamp)/86400);
   
$day_count_padded str_pad($day_count,3,"0",STR_PAD_LEFT);

    return (
$jde_year_prefix $jde_year_suffix $day_count_padded);
   
}

echo 
jde_date_create(6,25,2000);// will return '103176'

?>

--
Jim
curlee at mindspring dot com
29-Aug-2003 10:55
I solved a problem with Julian dates that are used in the JD Edwards ERP package (running on AS/400).  The Julian format for this system is as follows:  CYYDDD

Where C is 0 for 1900 and 1 for 2000
DDD is the day of the year count

I used the mktime built-in php function to convert dates to the normal DD/MM/YYYY format.  This function will convert dates that are between 1970 and 2038 (limitation of unix timestamps and the mktime function)

The $jde_date var needs to be a 6 len STRING.... if you use a numeric var type it will drop the leading 0 for any date that represents 1900.... this will botch the substr functions and thus make the whole thing wrong. 

function jde_date_conv($jde_date)
{

$ct = substr($jde_date,0,1);
$yr = substr($jde_date,1,2);
$dy = substr($jde_date,3,3);

if($ct == 0) $yr_pfx = 19;
if($ct == 1) $yr_pfx = 20;

$tlt_yr = $yr_pfx.$yr;

$base_time = mktime(0,0,0,1,0,$tlt_yr);

$unix_time = ($dy * 86400) + $base_time;

return date("m/d/Y" , $unix_time);
}
carlj at vibez dot ca
17-Jun-2003 02:28
Why not do something like this, to find the number of days in a month?

$monthNum = date("n"); // or any value from 1-12
$year         = date("Y"); // or any value >= 1
$numDays   = date("t",mktime(0,0,0,$monthNum,1,$year))

This will tell you if there is 28-31 days in a month
dy64 at dy64 dot de
12-Nov-2002 10:18
Best performance:
/*
 * Find the number of days in a month
 * Year is between 1 and 32767 inclusive
 * Month is between 1 and 12 inclusive
 */
function DayInMonth($month, $year) {
    var $daysInMonth = array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
    if ($month != 2) return $daysInMonth[$month - 1];
    return (checkdate($month, 29, $year)) ? 29 : 28;
}
gaoweibin at 163 dot net
26-Aug-2002 04:26
This is a Chinese Lunar Calendar, including SolarTerm, TianGan, DiZhi, DiesFaustus and Holidays.

http://211.161.46.3/gaowb/Calendar.php
kmcm at bigfoot dot com
21-Jan-2002 10:42
if, like me, you don't have a PHP build that includes the cal functions, you may want to use this function for sorting out leap year.

function days_in_feb($year){

    //$year must be YYYY
    //[gregorian] leap year math :
   
    if ($year < 0) $year++;
    $year += 4800;

    if ( ($year % 4) == 0) {
        if (($year % 100) == 0) {
            if (($year % 400) == 0) {
                return(29);
            } else {
                return(28);
            }
        } else {
            return(29);
        }
    } else {
        return(28);
    }
}

of course the next leap year isn't until the end of the century but this makes for timeless code I guess ...or if you are using 2000 in your dates or are going far back in time, etc, it is necessary.
mikebabcock at pobox dot com
17-Jul-2000 11:20
There are two world calculations for the date of Easter.  The Easter date function should account for this; one used (generally) by the Western world and one (generally) used by the Eastern (the official date used by the East Orthodox Church).
ssharma at odc dot net
31-Jan-2000 07:36
If you're interested in dates/calendars, check out the MCAL stuff.
http://www.php.net/manual/ref.mcal.php3

<bzwritecal_days_in_month>
 Last updated: Thu, 21 Aug 2003
show source | credits | sitemap | mirror sites 
Copyright © 2001-2003 The PHP Group
All rights reserved.
This mirror generously provided by: http://php.mirrors.ilisys.com.au/
Last updated: Sat 01 Nov 2003 04:13:36 EST EST