PHP - Calendar, Datepicker Calendar

The calendar component written in php script. It contains 2 modes: normal display calendar and date picker. See the demo below to check whether your browser support this script or not.
 
Demo:

Fixed Display Style

Date 1 :
  • Set default date to today date (server time)
  • Set year navigate from 1970 to 2020
  • Allow date selectable from 13 May 2008 to 01 March 2015
  • Not allow to navigate other dates from above
  • Disabled Sat and Sun

Code:

<?php
$myCalendar = new tc_calendar("date2");
$myCalendar->setIcon("calendar/images/iconCalendar.gif");
$myCalendar->setDate(date('d'), date('m'), date('Y'));
$myCalendar->setPath("calendar/");
$myCalendar->setYearInterval(1970, 2020);
$myCalendar->dateAllow('2008-05-13', '2015-03-01', false);
$myCalendar->startMonday(true);
$myCalendar->disabledDay("Sat");
$myCalendar->disabledDay("sun");
$myCalendar->writeScript();
?>

DatePicker Style

Date 2 :
  • Default date set to 01 March 2011
  • Set year navigate from 1960 to 2015
  • Allow date selectable from 01 January 2010 to 01 March 2015
  • Allow to navigate other dates from above

Code:

<?php
$myCalendar = new tc_calendar("date1", true);
$myCalendar->setIcon("calendar/images/iconCalendar.gif");
$myCalendar->setDate(01, 03, 1960);
$myCalendar->setPath("calendar/");
$myCalendar->setYearInterval(1960, 2015);
$myCalendar->dateAllow('1960-01-01', '2015-03-01');
$myCalendar->writeScript();
?>

DatePicker with no input box

Date 3 : 3 September 2010
  • Default date to current server date
  • Set year navigate from 2000 to 2015
  • Allow date selectable from 13 May 2008 to 01 March 2015
  • Allow to navigate other dates from above
  • Date input box set to false

Code:

<?php
$myCalendar = new tc_calendar("date5", true, false);
$myCalendar->setIcon("calendar/images/iconCalendar.gif");
$myCalendar->setDate(date('d'), date('m'), date('Y'));
$myCalendar->setPath("calendar/");
$myCalendar->setYearInterval(2000, 2015);
$myCalendar->dateAllow('2008-05-13', '2015-03-01');
$myCalendar->setDateFormat('j F Y');
$myCalendar->writeScript();
?>

Date Pair Example

from:
30-Aug-2010
to
05-Sep-2010

Code:

<?php					
$myCalendar = new tc_calendar("date3", true, false);
$myCalendar->setIcon("calendar/images/iconCalendar.gif");
$myCalendar->setDate(date('d', strtotime($date1)) , date('m', strtotime($date1)) , date('Y', strtotime($date1)));
$myCalendar->setPath("calendar/");
$myCalendar->setYearInterval(1970, 2020);
$myCalendar->writeScript();

$myCalendar = new tc_calendar("date4", true, false);
$myCalendar->setIcon("calendar/images/iconCalendar.gif");
$myCalendar->setDate(date('d', strtotime($date2)) , date('m', strtotime($date2)) , date('Y', strtotime($date2)));
$myCalendar->setPath("calendar/");
$myCalendar->setYearInterval(1970, 2020);
$myCalendar->writeScript();
?>

Example of submiting value: click here

Download zip file: calendar.zip (21.02 KB.)
Version 3.2 (Last update 13 August 2010)

What's new

v3.2

  • Bug fixed: Some confusion in date display when both dateAllow and setYearInterval are set in some cases
  • Bug fixed: add 'zindex' property to tc_calendar, helps in overlapping component (ie6)
  • Changed: Year navigate from newest to oldest

v3.1

  • Function added: disabledDay (thanks to Jim R.)
  • Day style adjustable with css (.mon, .tue, .wed, .thu, .fri, .sat, .sun)

v3.0

  • Bug fixed: day combobox not update (February case) when select date from calendar
  • Bug fixed: auto resize not applied when calendar start in hide div mode (display: none;)
  • Bug fixed: day combo box not update when selecting date < 10 (occured from v2.9)
  • Bug fixed: (18 May 2010) glich on IE7 update on calendar_form.php and calendar.css
  • Bug fixed: (22 May 2010) parseInt error on calendar.js function isDateAllow()

v2.9

  • Auto adjust calendar size (width & height)
  • Bug fixed: Valid day combo box when selecting month or year (input box mode)

Download tc_calendar with language pack (by Ciprian)

Demo: http://www.ciprianmp.com/scripts/calendar/
Download: http://www.ciprianmp.com/scripts/calendar/calendar_localized.zip

How to setup:

Only 2 steps requires for setup and use this calendar component.

Put the javascript file(.js) in the head section or somewhere else but it should be include once in a page.

<head>
<script language="javascript" src="calendar.js"></script>
</head>

Create form element in the html and put the following code

<form action="somewhere.php" method="post">
<?php
//get class into the page
require_once('classes/tc_calendar.php'); //instantiate class and set properties $myCalendar = new tc_calendar("date1", true);
$myCalendar->setIcon("images/iconCalendar.gif");
$myCalendar->setDate(1, 1, 2000);
//output the calendar
$myCalendar->writeScript();
?> </form>

How to get the value?

To get the date selected in calendar by php after submit the form, simple write script as the following:

<?php
$theDate = isset($_REQUEST["date1"]) ? $_REQUEST["date1"] : "";

?> 

The above script should be on another file that html form point to. The parameter 'date1' is the object name that you set in the code at the time calendar construct. See further in Functions and Constructor below.

To get the date selected by javascript on the current page, write script as the following:

<form action="somewhere.php" method="post" name="form1">
<?php
//get class into the page
require_once('classes/tc_calendar.php'); //instantiate class and set properties $myCalendar = new tc_calendar("date1", true);
$myCalendar->setIcon("images/iconCalendar.gif");
$myCalendar->setDate(1, 1, 2000);
//output the calendar
$myCalendar->writeScript();
?> </form> //use javascript to get the value <script language="javascript"> <!-- function showDateSelected(){ alert("Date selected is "+document.form1.date1.value); } //--> </script> //create link to click and check calendar value <a href="javascript:showDateSelected();">Check calendar value</a>

Functions

Constructor

tc_calendar (string bindObjectName)

tc_calendar (string bindObjectName, boolean date_picker)

tc_calendar (string bindObjectName, boolean date_picker, bool show_input)

date_picker default value is false.
show_input default value is true

Methods

autoSubmit (bool flag, string form_name, string target_url)

Specify the calendar to auto-submit the value. Default value of autosubmit is false

To set calendar auto submit, specify flag to true and you need to specify either form_name or target_url to make the calendar to perform autosubmit correctly

Ex 1. $myCalendar->autoSubmit(true, "myForm");
//assume that the calendar is in the form named 'myForm', then tell the calendar to auto submit the value (other values in myForm will be submitted together by html post method)

Ex 2. $myCalendar->autoSubmit(true, "", "anywhere.php");
//tell the calendar to submit the value to 'anywhere.php'. This method will submit only calendar value via html get method

dateAllow (date from, date to, bool navigate_not_allowed_date)

Specify date range allow to select. Other dates from input will be disabled. The parameter navigate_not_allowed_date will handle the user to navigate over the disable date, default is true (means allow)

Specify both date from and to will set range of date user can select.
Specify only date from or to will set range from/upto year set by setYearInterval method.

Ex 1. $myCalendar->dateAllow('2008-05-13', '2010-03-01', false); //allow user select date from 13 May 2008 to 1 Mar 2010
Ex 2. $myCalendar->dateAllow('2008-05-13', '', false); //allow user select date from 13 May 2008 upto whatever can navigate
Ex 3. $myCalendar->dateAllow('', '2010-03-01', false); //allow user select date from whatever can navigate upto 1 Mar 2010

disabledDay (string day)

Specify day column to be disabled. Possible day value: Mon, Tue, Wed, Thu, Fri, Sat, Sun

Ex. $myCalendar->disabledDay('Sun'); //disable Sunday column

getDate ()

Get the calendar value in date format YYYY-MM-DD

Ex. $myCalendar->getDate(); //return 2009-06-19

setDate (int day, int month, int year)

Optional: Set default selected date to the value input. For month parameter: January=1 and December=12

Ex. $myCalendar->setDate(15, 6, 2005); //Set the date to 15 June 2005

setDateFormat (string format)

Optional: Set the format of date display when no input box. Apply with 'showInput' function

Ex. $myCalendar->setDateFormat('j F Y'); //date will display like '9 September 2009'

setIcon (string url)

Optional: Set icon in date picker mode. If the icon is not set the date picker will show text as link.

Ex. $myCalendar->setIcon("images/iconCalendar.gif");

setHeight (int height) - deprecated since v2.9 - auto sizing applied

Optional: Set height of calendar. Default value is 205 pixels

Ex. $myCalendar->setHeight(205);

setPath (string path)

Optional: Set the path to the 'calendar_form.php' if it is not in the same directory as your script. The path string is a relative path to the script file.

Ex. $myCalendar->setPath("folder1/");

setText (string text)

Optional: Set text to display. The text will show in date picker mode when the icon is not set.

Ex. $myCalendar->setText("Click Me");

setWidth (int width) - deprecated since v2.9 - auto sizing applied

Optional: Set width of calendar. Default value is 150 pixels

Ex. $myCalendar->setWidth(150);

setYearInterval (int year_start, int year_end)

Optional: Set the year start and year end display on calendar combo box. Default value is +15 and -15 from current year (30 years)

Ex. $myCalendar->setYearInterval(1970, 2020);

showInput (bool flag)

Optional: Set the input box display on/off. If showInput set to false, the date will display in panel as example above 'DatePicker with no input box'. Default value is true

Ex. $myCalendar->showInput(false);

startMonday (bool flag)

Optional: Set whether the calendar will be start on Sunday or Monday. Set flag to true means the calendar will display first date as Monday, otherwise false will display first date as Sunday. Default value is false.

Ex. $myCalendar->startMonday(true);

writeScript()

Write the output calendar to the screen

 

 
Visitor Review  Write a review

desi Tec Huetamo on 02 Sep 2010 21:38 reply

Muchas gracias jala chido.

 

Francesco on 02 Sep 2010 10:47 reply

Hi!
Very very nice work :)

I'm testing your calendar script here (http://www.bbflorencerooms.com/prova/index2.php) but i have some little problem, i hope you help me to solve:

1) i'd like that at the start the calendar show the date of today and not "01 Jan 1970", is possible?

2) i need to send data value like "dd/mm/yyyy" and not "yyyy-mm-dd", is possible?

Thanks for your help,
bye bye

 

Andreas on 01 Sep 2010 06:31 reply

Hi,

A very nice tool.

But I found a error in the localization. In lang/localization.lib.php on line 12.
You must change (isset($hl) ? $hl : L_LANG) to ($hl ? $hl : L_LANG) twice.
On line 11 $hl is set to $_REQUEST['hl'] or false. isset($hl) is then ever true.

The DatePicker with no input box falls into english, when a new date is selected over the DatePicker.
I see the problem on postings here. Please check the solution.

Many Thanks for the great script.

Vince on 01 Sep 2010 15:11 reply

Hey Andreas :-)
Which version are you using? 3.2 or 3.1??

I was with 3.1 which has language pack... but now with 3.2, and there's no language pack at all neither Hl var... to swap language... :~
Do u know anything about that?? I'd like to swawp from a languae to another in 3.2... but seems we can not anymore :-((
Andreas on 02 Sep 2010 02:40 reply

Hi,

Its the version 3.1 from http://www.ciprianmp.com/scripts/calendar/calendar_localized.zip

I think the localization is a additional feature from www.ciprianmp.com and built in in version 3.1.


 

Mauro on 30 Aug 2010 15:27 reply

Hi all
i have now tried many hours to implement this script (fixed display style)- at me it doesn't work. I'm shure that somewhere i have a bug, but i don't know where.
Could please anyone post his implement-code (with pathes), that i can find my fault?
Thanks very much!!!

Mauro on 01 Sep 2010 14:47 reply

Is there really nobody who can help me with posting his code?
 

angelo on 30 Aug 2010 12:16 reply

very cool piece of software but i need to save the variable

any one knows how..

 

Sravanthi on 30 Aug 2010 09:59 reply

This is a very good software piece. and it helped me during the creation of update forms from the database. Thank you soo muchhh

 

Vince on 29 Aug 2010 11:32 reply

Anybody knows how to change calendar language with new v.3.2?? :-)

v3.1 had language packs and var $hl = L_LANG;

but this disappearded in 3.2 !

 

Salve on 28 Aug 2010 20:58 reply

Hi,

I used your script on a DokuWiki-install, which requires all addons to put its javascript in one file which is then compressed (line endings and commends are removed).

This resulted in a couple of errors which disabled all javascript on the site, as lines 34 and 224 in your calendar.js file are missing semicolons at the end.

Just a tip, thanks for the great script!

 

Vince on 27 Aug 2010 18:01 reply

Hi there! Congratulations for your great calendar. Working great with firefox.. but having hard time with IE 8, which justify calendar to the left side of the navigator.
Moreover in the new v3.2, there's no "lang" folder with al language packs!!? as well, is there a way to pass lang from our form to the 'tc_calendar.php'? Please let me know
Anyways, Thanks buddy you're making web developer life easier!! :-)

Vince on 27 Aug 2010 18:14 reply

in v3.1 I was able to pass through language regarding site language doing this: var $hl = L_LANG;
but in 3.2 var hl and L_Lang are not there anymore. what happened? :)
thks

Vince on 29 Aug 2010 10:58 reply

Hey! I found a quick fix to my issue, I use v3.2 but change css file with the css from v3.1 not having some positioning issue in ie 8 anymore. however haven't tested in ie6 yet...

Shrikant you should try that for your overlapping issue.

I'm still trying to figure out how to change language with v3.2!!! Anybody can help me??? :-)
 

riya on 27 Aug 2010 17:16 reply

thank you so much.........helped a lot!!....
Thankyou for making it simple to understand.

 

angie on 25 Aug 2010 13:53 reply

Hi!
I am working on online appointment system cnt really implement the password and confirm password chk neither in js nor php what to do ;(

 

fhount on 24 Aug 2010 13:11 reply

Thx you very much, this really helped me

 

May on 23 Aug 2010 13:55 reply

Sorry, but does it work for you with google chrome on macOs ?
cause when clicking the calender icon, the calender do not show up..! thanks for helping out

 

Asher on 23 Aug 2010 13:21 reply

I have anyother question, as i said before im using the calendar as an Effective date for an address change page, when subminted it display all the information on a comfirmation page. If they need to change something calendar displays the current server date not the date selected. I was wondering if there is a way to have it display the selected date when it returns to the page but on the 1st visit it display current server date?

 

Jagatha on 23 Aug 2010 07:33 reply

Great Tool and Thank you.
I have a small question perhaps you can help me.
Q: If I place the calender in 2 consecutive rows, ( Date picker style) and when I click on the calender on the first line, it shows behind the list boxes on the below line.
something like
<?php
$myCalendar = new tc_calendar("date1", true);
..................................
$myCalendar->writeScript();
?>
<br>
<?php
$myCalendar = new tc_calendar("date2", true);
.................................
$myCalendar->writeScript();

?>

Thanks in advance.

 

luie on 20 Aug 2010 04:48 reply

hello,
how do i set this up with TBS template, TBS is tunybutstrong?
thanks

 

armine on 19 Aug 2010 02:12 reply

nice tool!

but i want to setDate (the selected last date)
going back to the main form..
any suggestions?

tnx!

 

ai24 on 19 Aug 2010 02:09 reply

nice tool!

but i want to setDate (the selected dated )
any suggestions?

tnx!

 

Neeraj Gupta on 18 Aug 2010 09:56 reply

hello ,
i am using this calendar tool for my client website.

i am using the date 1 format but i don't want to display the calender icon or link there .

how can i do that ..???


thanks in advance !!

 

Sammy Mwaura on 18 Aug 2010 09:44 reply

Hi,
This php calendar script is great and I like it. However, I think when one selects the 'date to' smaller than 'date from' (in the date pair example), it should alternate the dates in the fields to read correctly. For example, if I select 'date from' as 18-Aug-2010 and 'date to' as 10-Aug-2010, then it should alternate the dates in that 'date from' picks the largest out of the two. Alternatively, we can have an alert showing the user the mistake or a prompt before alternating.

Thanks...

Regards,

Sammy

 

Baidyalal Mahalik on 18 Aug 2010 06:29 reply

its not the prpper way of a programme. i did not understand anything. please make some easy.

 

kevin on 17 Aug 2010 00:11 reply

works great what i want to know is there any option to change the background colour for selected dates? for example i rent out my caravan and hilighting the days i have available in green would be good and the booked in red for example.

thanks

 

D on 16 Aug 2010 10:38 reply

Very easy to install and very customizable.

Is there a way to automatically close the calendar pop up if the user clicks away from the calendar?

 

Peter Knight on 14 Aug 2010 16:24 reply

Hi,

Great script. I am having problems using the date I acquire to retrieve data from database. I am using the same code which I currently use successfully and I know that the date is being parsed over from one page to another as the echo is correct, but it just seems to ignore the date in the select statement. Any ideas? - The code from the page is below - config.inc provides the connection information

<?php
header ( "Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0");
header ("Pragma: no-cache");
$mydate = isset($_REQUEST["date5"]) ? $_REQUEST["date5"] : "";
echo("value of date submit = ".$mydate);
$submenu = "none";
require ("header.php");
$PageTitle = "Latest Cinema and Exhibition Industry News";
// Set the variables for the database access:
include ("config.inc");
$TableName = "main_news";
$Link = mysql_connect ($host, $user, $password);
$Query = "SELECT * from $TableName WHERE $mydate = Date";
Print ("<h2>The Latest Cinema and Exhibition Industry News for $mydate</h2>\n");
$Result = mysql_db_query ($database, $Query, $Link);
// Fetch the results from the database.
while ($Row = mysql_fetch_array ($Result)) {
print("<p><b>$Row[Date]</b><br><b><a href=$Row[url] target=_blank>$Row[NewsStory]</a></b> - $Row[description]<br><b>Source:</b> $Row[source] <b>Editor:</b>$Row[Editor]</p><hr>\n");
}
mysql_free_result($Result);
mysql_close ($Link);
require ("footer.php");
?>

 

Shrikant on 12 Aug 2010 09:13 reply

Hi.. No doubt its one of the best calendar i found on net in regards with PHP n Javascript.
But i m facing problem in IE.

As i have placed 2 calendars in 2 rows and there is some dropdown field in third row now whenever im opening the 2nd calendar wherever drop downs are coming below that calendar they get visible over the calendar its looks odd and confusing any way out to resolve this i hope u get my issue

TJ on 13 Aug 2010 13:36 reply

Hi, I can get this fixed by using doctype as below

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>

Place the above doctype before open html syntax

others doctype could work also such as

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

I hope this is the correct issue for you ;)

Shrikant on 13 Aug 2010 14:31 reply

Hi thanks for the quick reply but in vain i tried both of the document definition.
In IE 6.0 it is not working at all even it use to get stuck when we are trying to change the calendar month and drop issue is still there.. Any response will be highly appreciated for the same.
TJ on 13 Aug 2010 15:48 reply

Hi, please try the latest issue (v3.2) I just add 'zindex' property to tc_calendar class

then you need to specify it by

//Calendar 1 initiate
...
$myCalendar->zindex = 100;
$myCalendar->writeScript();

//Calendar 2 initiate
...
$myCalendar->zindex = 90;
$myCalendar->writeScript();

then the calendar #1 container will have higher z-index than calendar #2

this should helps ;)
Shrikant on 13 Aug 2010 18:27 reply

Thanks for the reply will implement the same and will try to test it and let you know the result actually i don't have version 6 at home so cant test it. I hope you have also fixed that changing calendar year or month issue as it used to get stuck and display only half calendar due to some error in JavaScript acc to IE 6

Shrikant on 15 Aug 2010 00:56 reply

hi its still not working in IE 6. The drop down issue overlapping issue is still there and even it gets hang when we try to change the calendar month or year in IE6
for other browsers its working fine but now with ie6.
 

Grisda on 11 Aug 2010 23:25 reply

First of all, Thank so much for this excellent code. It's very useful calendar..

I am trying to use calendar picker in one of my form and use it it a date field called "start_date" ( input text field) all those data in the form will be written in the database. The problem that i am having that I don't know how to automatically update and show the value from calendar picker into my "start_date" once i have changed to date in calendar picker. I tried using function getDate(), unfortunately it doesn't work, it always show "0000-00-00". as below

echo"<input type='text' name='start_date' value=" . $myCalendar->getDate() .">";


Pleaes kindly advise..
Thank you very much


TJ on 13 Aug 2010 13:46 reply

Hi, the value in your textbox cannot dynamically update because it didn't link to the calendar object, and I think this is something very advanced and very difficult to do.

Why don't you use the dropdown style instead of textbox? I am still not sure what you are trying to do
 

Asher on 09 Aug 2010 13:34 reply

This is the best calendar code that i found and could understand :P Having said that I am having problems with the current versions of Google chrome and selecting a date outside of the current year.
I have the calendar installed on a page that has a confirmation screen that allows users to go back and change information if they made a mistake.
When the page “goes back” it set the date back to current date and when you try to change it to another the date range is from 1981 to 2040 and if try and select another month or year it just displays refreshing calendar.
I made the setyearinterval and dateallow dynamic to update the calendar each day and to only allow current and next year. Here is the code I used:
$myCalendar->setYearInterval(date('Y'), date('Y')+1);
$myCalendar->dateAllow($myCalendar->getDate(), "", true);

I also tried making these dates static and I get the same result. I don’t know what else I can try!

TJ on 13 Aug 2010 14:37 reply

hi, thank you so much for reporting error. I found the error and try to figure it out :p
Asher on 13 Aug 2010 14:39 reply

Thanks!

Asher on 23 Aug 2010 11:41 reply

Hey, i was just wondering how it was coming with the fix for this problem? Thanks again for your help on it!
 

CertifiedGeek on 06 Aug 2010 13:36 reply

Not scalable, tanks when using a MVC setup. An improvement would be adding a config file to setup paths to the files

 

M1928M on 03 Aug 2010 13:56 reply

This is a great tool! Thanks for developing and sharing it!

I do have a couple of questions, is it possible to block certain dates from being selectable and is it possible to set the start date to two weeks from the current day so that it updates continuously?
I tried using $myCalendar->dateAllow((date('d')+14), date('m'), date('Y'), '2011-05-01', false); but that just made all dates unselectable.

Thanks for your help and again thanks for sharing your work!

TJ on 13 Aug 2010 14:27 reply

Hi, look like you set a wrong date on dateAllow's first parameter

$myCalendar->dateAllow((date('d')+14), date('m'), date('Y'), '2011-05-01', false);

it should be

$aDate = date('Y-m-d', mktime(0,0,0, date('m'), date('d')+14, date('Y'));

$myCalendar->dateAllow($aDate, '2011-05-01', false);
M1928M on 27 Aug 2010 10:28 reply

Thanks! I really appreciate the help!
 

bobnojio on 03 Aug 2010 13:17 reply

Looks and works great.
one problem found with $myCalendar = new tc_calendar("date1", true); however.
the calendar button does not load anything.
I have tried playing around with the "date1", true, false, values, etc. without changing any of my other references, and only on 'date1',true does the calendar NOT show up.

any ideas on a fix?

 
See all reviews 1 2 3 4 5 6 7 8 9 10 Next»
Write a review
Rating:
Text:
Name:
Email:
(optional)
 
Code:
 

Search this site