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 :

DatePicker Style

Date 2 :

Download zip file: calendar.zip ( 9.77 KB.)
Version 1.8 (Last update 16 Nov 2008)


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, simple write script as the following:

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

?> 

The above script should be in the 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.


Functions

Constructor

tc_calendar (string bindObjectName)

tc_calendar (string bindObjectName, boolean date_picker)

date_picker default value is false.

Methods

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

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");

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)

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);

writeScript()

Write the output calendar to the screen

 
 
Visitor Review Write a review

ahmed mahdi on 20 Nov 2008 06:55 reply

I really don't know what's wrong here is the code:

$startDate = isset($_REQUEST["date1"]) ? $_REQUEST["date1"] : "";
$endDate = isset($_REQUEST["date2"]) ? $_REQUEST["date2"] : "";

$start_timestamp = strtotime($startDate);
$end_timestamp = strtotime($endDate);

include_once('connection.php');

$result = mysql_query("SELECT * FROM table1 WHERE date BETWEEN

'$start_timestamp' AND '$end_timestamp'");

 

ahmed mahdi on 20 Nov 2008 06:13 reply

hi again, i have a problem .. i have a field in my database called date in it auto incript timestamp and i tried to use the datepicker to search between two date var but i got no results please help

TJ on 20 Nov 2008 06:53 reply

hi, I will contact you by email. I got your email in the previous review.
 

Nadin on 18 Nov 2008 16:58 reply

I tried to use this Date Picker, it seemed good at the start, but when I click on any of the dates it keeps on giving me this error:

"Forbidden

You don't have permission to access /Cal/< on this server."

My Form in in a folder called Cal in which I have:
Cal/calendar_form.php
Cal/calendar.css
Cal/calendar.jss
Cal/classes/
Cal/images
Cal/MyForm.php --> the form that uses the calendar..

What is the reason for this error? and why I am unable to use it well? I am new to php also..
And if there is a way to transform these drop-down lists in the date-picker to an input text box that will display the value I choose from the calendar??
Thanks a lot for help

TJ on 18 Nov 2008 23:33 reply

I'm not sure about the error you found but 'Forbidden' error normally caused from the permission of 'folder' on server is not allow to 'execute'. This means your folder named 'Cal' should be checked and set to be executed.

This is just my guess from your error reporting. If it is wrong, i'm sorry. Then contact me again and give me more information, I'm please to help you.

I'm not sure if there are any error from my latest issue (v 1.8) but I have re-checked it so many times. If anyone find it, please feel free to report back to us. Thank you.
 

Caloja on 17 Nov 2008 11:04 reply

Thanks a lot, it is very easy to use and it's a great
display. I used and works perfectly. Very Thank you.

 

mutawakil on 17 Nov 2008 08:53 reply

grat work

 

ahmed mahdi on 17 Nov 2008 08:01 reply

very helpful .. it comes in time i was building a request to some data between two dates for local intranet but i was disapointed because the users do not know the date format .. but now there is no problem ..

 

Denis on 15 Nov 2008 21:31 reply

I'm in Canada where there has been a slow transition from mm-dd-yyyy (American) to dd-mm-yyyy (European). At this point people are very confused with dates such as 10-12-2008 since they just don't know whether it means day/month or month/day. Until the new European standard is accepted and used widely, it would be very helpful to have a calendar that inserts the month as a word.

 

Denis on 15 Nov 2008 07:06 reply

This calendar looks great and performs beautifully. Is it possible to have the script output the month to the form field in words (January, February, March) rather than numbers (01, 02, 03)?

TJ on 15 Nov 2008 07:41 reply

Sorry! I don't get the idea why you want to get the month value in words
 

Denis on 14 Nov 2008 23:41 reply

When I wrote the post above, I included the "optional" email address so that you or others could respond. But why would you post email addresses right on the page? The robots have already harvested mine from this site and have started a spam bombardment.

Please remove my email address as soon as possible.

TJ on 15 Nov 2008 00:04 reply

Denis, I am really sorry for this. I just remove the email and try to improve this system
 

Chris on 13 Nov 2008 12:40 reply

I really like the program. You have saved me a lot of development time!

Just one question that I haven't been able to figure out on my own. Is there a way to make it post a unix timestamp rather than the human readable it does right now? Thanks!

TJ on 13 Nov 2008 23:24 reply

For Unix timestamp, I think you can try php function strtotime() after receiving the calendar value. For examples:

$date = isset($_REQUEST["calendar_name"]) ? $_REQUEST["calendar_name"] : "";

then you can get timestamp by

$date_timestamp = strtotime($date);

This should help.
 

Dan on 12 Nov 2008 09:17 reply

Great work. There's just a small inconsistency. Using the datepicker can result in single digit day and month values whereas the select boxes provide double digit values. A simple zeropad in selectDay() should do the trick. :)

 

Gabe on 11 Nov 2008 21:20 reply

Awsome work. I would welcome the ability to taylor where exactly the date picker shows up . I mean under the combo below to th eleft to the right. Thanks guys awsome work

 

simonzebu on 04 Nov 2008 07:02 reply

This looks like it should be really simple, but wherever I install it I end up with a top row of date links and the rest of the month un-clickable minus numbers. The dates do not match the days of the week correctly and the current date is displayed incorrectly.

I have tried installing the entire folder both remotely and locally, but the index page displays the calendar incorrectly as above. Can anyone help?

TJ on 05 Nov 2008 07:52 reply

could you please give me some of your codes involve with calendar script so that I will point out what is missing.
 

Henrik on 30 Oct 2008 06:45 reply

Hi. I love this, but i use two forms, date1 and date2 since I need a from-date and to-date. This works perfect, but is there a way i can get the second form to change its day after the first form?
I.e when i select date in the first form, the second form performs an onchange so the date is 1 day higher than the first selected date?

TJ on 05 Nov 2008 07:50 reply

to make the 2nd form select after 1st form is not possible for the calendar itself now. I think if you apply this to php script will be more easier.
 

Gordon Muir on 26 Oct 2008 14:32 reply

Excellent script.

How would I:

1. Make the calendar default to yesterday

2. Only allow dates in the past to be chosen

Thanks

TJ on 05 Nov 2008 07:45 reply

to make the calendar default to yesterday, you can try php date function like

date('Y-m-d', mktime(0,0,0, date('m'), date('d')-1), date('Y'));

and set this date to calendar.

for only allow dates in the past to be chosen is not possible for now
 

Lemons on 17 Oct 2008 14:43 reply

It works really well and installed just fine.

 

MudMonkey on 16 Oct 2008 13:59 reply

Great work. Really saves me from having to write out millions of <option> tags.

To have two on a page just simply do this in the form:

<?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, 11, 2008);

$myCalendar2 = new tc_calendar("date2", true);
$myCalendar2->setIcon("images/iconCalendar.gif");
$myCalendar2->setDate(1,11,2008);
//output the calendar
$myCalendar->writeScript();
$myCalendar2->writeScript();
?>

And this on the form's "action" page:

<?php
$startDate = isset($_REQUEST["date1"]) ? $_REQUEST["date1"] : "";
$endDate = isset($_REQUEST["date2"]) ? $_REQUEST["date2"] : "";

echo "The exhibition runs from ".$startDate." to ". $endDate;

?>

Thanks for the great script.

 

Luiz Augusto on 15 Oct 2008 13:23 reply

Nice job!

Is it possible to extend the values in combo year?
The first year showing in the combo is 1978 and the last one is 2038. I need it for a birth date, so I try to edit tc_calendar.php:
year_display_from_current = 30;
to:
year_display_from_current = 50;
But now, the combo starts at 1958 and after 2038 it's showing lots of 1969...

-------> [bug has been fixed, thanks for report and setYearInterval function has been added]

 

Novakane on 13 Oct 2008 20:32 reply

how would you have to of these on one page

i.e. Choose Start date and Then Choose End Date.

 

ken on 08 Oct 2008 00:37 reply

thanks really cool

2 things;

when the i submit the form via Get the url adds the date with a &date1_dp and is messing up my SQL, i tried removing the echo statement in tc_calendar, but that didnt work

Also, i changed the frane width of the panel, but that didnt seem to do anything.

Can you assist?

Otherwise, its great css was easily editable.

Thanks!

 

Blaine on 07 Oct 2008 19:08 reply

OK if this were any simpler it would install itself..

Well done!!!

 

Denis on 06 Oct 2008 15:01 reply

Re: PHP - Calendar, Datepicker Calendar. This seems very hard to understand. The "How to set up" page displays very little code to cut and paste. Nothing is said about the large javascript file in the download. And most important of all, with your instructions, you'll be having people place a form within their existing form. Is that intentional?

Make these issues clearer, please. I'd like to rate this high for simplicity, but that's just not possible.

 
Write a review
Rating:
Text:
Name:
Email:
(optional)
 
Code: