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 server date (Auto unset if date is disabled)
  • 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
  • Show calendar weeks

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 to current server date (Auto unset if date is disabled)
  • 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
  • Disable specific date 1, 13, and 25 of every month
  • Custom alert when calendar's value has been changed

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->setSpecificDate(array("2011-04-01", "2011-04-13", "2011-04-25"), 0, 'month');
$myCalendar->setOnChange("myChanged('test')");
$myCalendar->writeScript();
?> <script language="javascript">
<!--
function myChanged(v){
alert("Hello, value has been changed : "+document.getElementById("date1").value+"["+v+"]");
}
//-->
</script>

DatePicker with no input box

Date 3 :
  • No default 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
  • Set alignment left and bottom
  • Disable specific date 1, 4 April, and 25 December of every years
  • Disable specific date 10, 14 of every months
  • Disable 1 June 2011

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->setAlignment('left', 'bottom');
$myCalendar->setSpecificDate(array("2011-04-01", "2011-04-04", "2011-12-25"), 0, 'year');
$myCalendar->setSpecificDate(array("2011-04-10", "2011-04-14"), 0, 'month');
$myCalendar->setSpecificDate(array("2011-06-01"), 0, '');
$myCalendar->writeScript();
?>

Date Pair Example

from:

Code:

<?php					
$date3_default = "2012-01-30";
$date4_default = "2012-02-05";

$myCalendar = new tc_calendar("date3", true, false);
$myCalendar->setIcon("calendar/images/iconCalendar.gif");
$myCalendar->setDate(date('d', strtotime($date3_default)) , date('m', strtotime($date3_default)) , date('Y', strtotime($date3_default)));
$myCalendar->setPath("calendar/");
$myCalendar->setYearInterval(1970, 2020);
$myCalendar->setAlignment('left', 'bottom');
$myCalendar->setDatePair('date3', 'date4', $date4_default);
$myCalendar->writeScript();

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

Example of submiting value: click here

Download zip file: calendar.zip (31.42 KB.)
Version 3.68 (25 November 2011)

What's new

Version 3.68

  • [Fixed] 1st and 31st (on each month) are always disabled when running with php4

Version 3.67

  • [Fixed] Javascript possible error on Date.parse
  • [Fixed] Add on-change javascript in dropdown datepicker mode

Version 3.66

  • [Fixed] json checking function produce error when the php does not support for json

Version 3.65

  • [Fixed] Date selected hilight error
  • [Added] Auto hide calendar and make it default property
  • [Added] Auto focus an overlapping calendar to the top

Version 3.64

  • [Fixed] Incorrect parameter submited on javascript that caused an invalid date returned

Version 3.63

  • [Changed] Make the DatePair function selectable on any dates. Date-from must be before Date-to, and on the other hand, otherwise it will be reset

Version 3.62

  • [Fixed] Error displaying date on Jan 2012 and some other months

Version 3.61

  • [Added] Display weeks
  • [Added] RTL supported
  • [Added] startDate function for selecting any days as start day of week
  • [Adjusted] Rearrange source code on calendar_form.php

Version 3.60

  • [Added] Add X as background of disabled days
  • [Fixed] 'Day' combobox contain no list dropdown when not call setDate() on initialization
  • [Fixed] Fixed display style still have the default value in case of the date is disabled.
  • [Fixed] 'Today' date color disappear when date is disabled.
  • [Fixed] Javascript error from IE compatible not support for JSON
  • [Adjusted] Change the color of today date to green with border

Version 3.59

  • Update to match the version with localization

Version 3.58

  • [Fixed] the value of calendar is not restored when using back button on browser

Version 3.57

  • [Fixed] update calendar.css display glitch

Version 3.56

  • [Fixed] error on checkSpecifyDate, calendar.js

Version 3.55

  • [Fixed] 'dateAllow' contains error on calendar_form.php

Version 3.54

  • [Update] 'setSpecificDate' to set on month, year, and no recursive simultaneuosly
  • [Added] 'setOnChange' to customize onChange event of calendar

Version 3.53

  • [Fixed] writeYear contains unused variable (error), sorry guys :(

Version 3.52

  • [Fixed] datepair error after cleaned up code (on version 3.50)

Version 3.51

  • [Added] check_json_encode and check_json_decode for the server that not support json

Version 3.50

  • [Added] setSpecificDate to enable or disable date specified
  • [Improved] Cleaning up and more validating source codes (thanks to Peter)

Version 3.41

  • [Fixed] calendar header - look tight
  • [Fixed] Using incorrect path on example file (index.php), forgot to add history logs on class file

Version 3.4

  • [Added] setAlignment
  • [Added] setDatePair

Version 3.3

  • [Fixed] Total number of days in datepicker mode on startup incorrectly appear (thanks to Francois du Toit, ciprianmp)

Version 3.2

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

Version 3.1

  • [Added] disabledDay (thanks to Jim R.)
  • [Improved] Day style adjustable with css (.mon, .tue, .wed, .thu, .fri, .sat, .sun)

Version 3.0

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

Version 2.9

  • [Improved] Auto adjust calendar size (width & height)
  • [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

Copyright
This calendar datepicker is totally free to use. You can use it in all of your projects without any costs.
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>

Calendar Properties

rtl - specify the right-to-left direction of calendar

Ex. $myCalendar->rtl = true;

zindex - specify the zindex value to calendar

Ex. $myCalendar->zindex = 99;

Calendar 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

setAlignment (string horizontal_align, string vertical_align)

Optional: Set the alignment of calendar datepicker with the calendar container. The value of horizontal alignment can be 'left' or 'right' (default) and the value of vertical alignment can be 'top' or 'bottom' (default).

Ex. $myCalendar->setAlignment('left', 'top');

setAutoHide (bool auto, int delay_time)

Optional: Set an auto hide of calendar when not active. The calendar has default value of auto hidden since version 3.65 with default delay time of 1000 (1 second)

Ex 1. $myCalendar->setAutoHide(true, 3000); //auto hide in 3 seconds
Ex 2. $myCalendar->setAutoHide(false);

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'

setDatePair (string calendar_name1, string calendar_name2, string default_pair_value)

Optional: Set a date pair link to calendar object. This function will work when 2 calendars are setup together.

Ex 1. $myCalendar->setDatePair('date1', 'date2'); //This means when the value of calendar 'date1' is set, the calendar 'date2' will not allow to select the date prior to 'date1'
Ex 2. $myCalendar->setDatePair('date1', 'date2', "2011-03-26"); //suppose you are setting this value on date1 object, '2011-03-26' will be assigned as default date of date2 and calculated

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

setOnChange (string value)

Optional: Set the onchange javascript function to calendar

Ex. $myCalendar->setOnChange("javascriptFunctionName()");

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

setSpecificDate (array dates, int type, string recursive)

Optional: Set the specific to enable or disable.

dates: the array of date, and date should be in format YYYY-MM-DD
type: enable or disable the date specified. 0=disable, 1=enable
recursive: '' (blank)=no recursive, calendar will process only on exact date, 'month'=monthly recursive, or 'year'=yearly recursive

Ex 1. $myCalendar->setSpecificDate(array("2011-04-22"));
Ex 2. $myCalendar->setSpecificDate(array("2011-04-22"), 0, 'month'); //disable date 22 every month
Ex 3. $myCalendar->setSpecificDate(array("2011-04-22"), 0, 'year'); //disable 22 Apr on every year

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

showWeeks (bool flag)

Optional: Display weeks on calendar upon setting. Default value is false.

Ex. $myCalendar->showWeeks(true);

startDate (bool date_number)

Optional: You can choose any day as a start day of week. The possible values are 0 (for Sunday) through 6 (for Saturday). Default value is 0 (Sunday)

Ex. $myCalendar->startDate(6); //start day of week is Sat.

startMonday (bool flag) - deprecated since v3.61 - use startDate instead

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
Search Review :

David Morse on 04 Feb 2012 09:36 reply

This is a great calendar; I have one occurring problem though. I use the calendar in an online reservation form for a restaurant, but I still find that some people are able to post a reservation without choosing a date, is there a way I can force them to pick a date? I have the calendar set up so that people cannot choose today's date, but I get bookings from people with the date Thursday 01 January 1970; and asking for today?

 

ren on 02 Feb 2012 06:59 reply

thank very much !
it is working the way I wanted it
wow!

 

danny on 02 Feb 2012 06:43 reply

i have tried to use the pair date in my form but i dont get well where the codes above get well used,

foristnce my codes are as below,and i need where exactly should i insert the date pair code to get functioning properly

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script language="javascript" src="calendar.js"></script>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>

<body>
<html><style type="text/css">
<!--
body {
background-color: #CCCCCC;
}
.style1 {
color: #FFFFFF;
font-weight: bold;
}
-->
</style>
<form id="form1" name="form1" method="post" action="">

<table width="504" border="0">
<tr bgcolor="#999999">
<tr>
<td colspan="4">Enter the corresponding <label></label>inquiry date please! </td>
</tr>
<tr>
<td width="92"><label><div align="center">
<p>&nbsp;</p>
<p>AS FROM </p>
</div></label></td>
<td width="145"><label> <br />
<br />
<br />
<input type="text" name="textfield" />
<br />
</label></td>
<td width="63"><div align="center"><label></label>
<p>&nbsp;</p>
<p>TO</p>
</div></td>
<td width="186"><label> <br />
<br />
<input type="text" name="textfield2" />
</label></td>
</tr>
<tr>
<td colspan="4"><label>
<div align="center">
<p>
<input type="submit" name="Submit" value="Submit" />
</p>
</div>
</label></td>
</tr>
</table>

</form>
</body>
</html>

 

yumino on 02 Feb 2012 05:33 reply

Hi,

It seems to be a problem with the February month.
Since two days, i have these following error :

Notice: A non well formed numeric value encountered in C:\wamp\www\sous-domaine\httpdocs\fichiersv2\calendar\tc_calendar.php on line 711
mktime ( ) ..\tc_calendar.php:711

Notice: A non well formed numeric value encountered in C:\wamp\www\sous-domaine\httpdocs\fichiersv2\calendar\tc_calendar.php on line 641
mktime ( ) ..\tc_calendar.php:641

Anyone have an idea about it ?

 

BJL on 26 Jan 2012 11:22 reply

There seems to be a bit of problem with the "dateAllow" fuction.

You can see the error in the example you have on the page. You show "Allow date selectable from 13 May 2008 to 01 March 2015".

However, if you go to March 2015 you will see that 01 March 2015 is NOT allowed.

Perhaps that is how you wanted it to work but that does not seem correct to us.

Do you reall mean that the date allowed is greater than or equal to the "date from" and less than the "date to" parameters?

Let us know if we should assume that is how you intend it to work.

Thanks for a great tool and all your efforts, they are appreciated

BJL on 27 Jan 2012 13:00 reply

It appears the problem we reported is related to the use of the PHP function "strtotime" and the related function "strtotime" that is in the JavaScript program and the use of the JavaScript "date" object.

The PHP version of "strtotime" converts the text date into a Unix time stamp BASED on the current value of the "default time zone".

However the JavaScript program that emulates the "strtotime" function does not have any reference to a time zone.

Furthermore the "date" object used in the JavaScript itself uses the "local" time zone.

So it looks like if the PHP script is running in a different time zone than the JavaScript, the time stamp could be off a few hours.

This leads to the comparison being incorrect and we see the behavior outlined in this post as well as demonstrated on this web page.

The core problem occurs since the PHP code changes the date to a Unix time stamp and passes the TIME STAMP to the JavaScript.

Then when checking the date, the JavaScript uses its own conversion of a date into a time stamp based on a different time zone. Any comparison of these two time stamps will be a problem.

It appears this is occurring in a number places in the code where a time stamp generated on the server is being compared to a time stamp generated on the client (JavaScript).

The only fix we can think of would require a re-write to pass a text version of the date to the client and let any time stamp conversions be done there and used for comparison.

We hope you do get a fix for this, let us know when it is available.

Thanks for the help.
 

gg on 23 Jan 2012 20:43 reply

Sorry I already commented on a similar post, but I didn't want my response to be lost in all the reviews.

After browsing though comments for past 4 hours trying various solutions posted here I'm still having issues with drop down boxes submitting the original date. Has anyone figured this out? I would really prefer to ONLY use drop down boxes

 

Sara on 19 Jan 2012 14:59 reply

Hello,
I am trying to use Date Pair Example that displays default dates in the box. When clicking the calendar, I get the following error:
Warning: date() expects parameter 2 to be long, string given in /work/tests_framework/php_lib/calendar/calendar/calendar_form.php on line 254

Warning: date() expects parameter 2 to be long, string given in /work/tests_framework/php_lib/calendar/calendar/calendar_form.php on line 254

The warning is related to the following line:
$myCalendar->setDate(date('d', strtotime($date3_default))
, date('m', strtotime($date3_default))
, date('Y', strtotime($date3_default)));

Your help would be very much appreciated.
Thanks,
Sara

 

RJ on 19 Jan 2012 04:46 reply

just a correction:

2 0.0011 404920 include( 'C:\wamp\www\SERVER\view\addapplicant.php' ) ..\index.php:72

it should be
2 0.0011 404920 include( 'C:\wamp\www\SERVER\view\body.php' ) ..\index.php:72

 

RJ on 19 Jan 2012 04:32 reply

Hi this is a great script. But i have mine a problem. There is an error although the drop down are showing.

Err:
Notice: Use of undefined constant L_LANG - assumed 'L_LANG'

1 0.0004 383176 {main}( ) ..\index.php:0
2 0.0011 404920 include( 'C:\wamp\www\SERVER\view\addapplicant.php' ) ..\index.php:72
3 0.0039 701840 require_once( 'C:\wamp\www\SERVER\calendar\tc_calendar.php' ) ..\body.php:24
4 0.0060 986368 include_once( 'C:\wamp\www\SERVER\calendar\lang\localization.lib.php' ) ..\tc_calendar.php:155

The setup of my folder is
Server
calendar(folder)
images(folder)
lang(folder)
tc_calendar.php
calendar.js
calendar_form.php
views(folder)
body.php
index.php

index.php

<?php include("views/body.php") ; ?>

body.php

<?php require_once('calendar/tc_calendar.php');
$myCalendar = new tc_calendar("date2", true);
$myCalendar->setIcon("calendar/images/iconCalendar.gif");
$myCalendar->setDate(date("d"), date("m"), date("Y"));
$myCalendar->setPath("calendar/");
$myCalendar->setYearInterval(1960, date("Y"));
$myCalendar->dateAllow("1960-01-01", date("Y-m-d"));
$myCalendar->setAlignment("left", "bottom");
$myCalendar->setSpecificDate(array("2011-04-01", "2011-04-14", "2010-12-25"), 0, "year");
$myCalendar->disabledDay("sun");
$myCalendar->writeScript();
?>

What did i do wrong here?

Many Thanks

ciprianmp on 19 Jan 2012 15:32 reply

RJ, that's a warning error, which should not be displayed on production websites. You need to configure your php.ini (error_reporting) of your server, to hide warning errors.

ciprianmp on 19 Jan 2012 17:53 reply

Are you sure you're using the latest version of the localized calendar? I couldn't replicate this notice...
RJ on 19 Jan 2012 19:17 reply

Hi Ciprianmp,

Thank you so much for your time. i downloaded the localized, should not be. Thank you for pointing it out. I read the whole part and missed out on the download part. It is ok now. :-)

Many Thanks and More power.
ciprianmp on 20 Jan 2012 12:15 reply

You're very welcome!
 

vie on 17 Jan 2012 02:49 reply

how to change the format of value?
*not setDate();

i want to set the format Y-M-d to d-M-Y

*sorry for my bad english

 

Emiliano on 16 Jan 2012 08:52 reply

Hi! It's possible to select the date through Javascript?

 

Nik on 15 Jan 2012 18:20 reply

Great calendar, really easy to understand&use... implementing it now into my project. Thank you very much, you saved my time.

 

steph on 15 Jan 2012 05:51 reply

Update: I moved the line "require_once" out of the form field and into the header. This allowed the rest of my form to display, HOWEVER....

I have dynamic drop-down fields that are populated with include files that query database. Although the input boxes now display, they do not populate. Something is preventing the call to the include files.

Any ideas?
Thanks again.

 

steph on 15 Jan 2012 04:02 reply

LOVE this-cannot get jquery to work AT ALL and this ACTUALLY WORKS!!!

ONE ISSUE-the rest of my form/script stops working after the calendar script. any ideas?
This is the first input box in a whole form and the rest of the form doesn't work. ive tried changing the require_once to include, but i'm not even certain if that is the problem.

any help would be appreciated.
thanks! and thanks for making a form calendar that actually WORKS!

 

ugla on 12 Jan 2012 22:18 reply

I want to insert the value of the selected date into MYSQL, but I really can't find out how..

I added this in the header:
$mydate = isset($_POST["date1"]) ? $_POST["date1"] : "";
$mydate = strftime("%Y-%m-%d", strtotime($mydate)); // mysql-format

mysql_query("INSERT INTO book (date) VALUES ('".$mydate."')

Why isn't it that simple? Please help me out!:)

ugla on 12 Jan 2012 22:21 reply

( I didn't forgot the " ; " in the mysql_query ) :P

ciprianmp on 13 Jan 2012 00:30 reply

$mydate had the needed format already...
ugla on 13 Jan 2012 05:41 reply

Yeah, but that's not the problem :)
Please help..
TJ on 13 Jan 2012 06:16 reply

Can you figure out the error message which is return from this?

ciprianmp on 13 Jan 2012 10:46 reply

Are you sure the 'date' field has the "mysql date format" ? which is "YYYY-MM-DD"?
Is your form name "date1"?
Try:
mysql_query("INSERT INTO book (date) VALUES ('".$mydate."')");
The ending of the line was incomplete...

I can't see another reason for an error for now...

steph on 15 Jan 2012 14:03 reply

ugla-here is how you do it to get it into mysql date format:

$mydate = isset($_REQUEST["date1"]) ? $_REQUEST["date1"] : "";

It automatically comes in formatted as "yyyy-mm-dd", just as mysql requires for successful database insert. try it with an echo statement and you'll see.

echo "mydate is: " . $mydate . "<br />";

hope this helps.
 

Pierre, Sweden on 12 Jan 2012 17:52 reply

Excellent datepicker!

When I use 2 datepickers, is it possible somehow to set the date on 2nd datepicker to be the a date value from the 1st datepicker? Sometimes I need to add a 2nd date (end date) but I can't find a cunning way of making this easy for the user without several clicks on year and months. I use 2 datepickers with dropdowns for day, month and year.

steph on 15 Jan 2012 14:10 reply


pierre, the below code is the setup for the 2nd datepicker on your page. here's how you can set the first date to populate as the default for the second date:
(look at the if statement inside the setup script).

**********
<?php
$myCalendar = new tc_calendar("date2", true, false);
$myCalendar->setIcon("calendar/images/iconCalendar.gif");
if(isset($date1))
{
$myCalendar->setDate(date('d', strtotime($date1)), date('m', strtotime($date1)), date('Y', strtotime($date1))); }
else
{
$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->setAlignment('left', 'bottom');
$myCalendar->setSpecificDate(array("2011-04-01", "2011-04-04", "2011-12-25"), 0, 'year');
$myCalendar->setSpecificDate(array("2011-04-10", "2011-04-14"), 0, 'month');
$myCalendar->setSpecificDate(array("2011-06-01"), 0, '');
$myCalendar->writeScript();
?>

*******************
hope this helps.
steph on 15 Jan 2012 14:23 reply

Update-you may need an onchange event in your element (input, select, etc) to trigger a reload of the form once the user has selected the first date.

here's some code for that:

Put this in your header:
<!-- Function to reload form & populate 2nd date once first date is chosen -->
<script type="text/javascript">
function reload(form)
{
var val=form.fdate1.options[form.fdate1.options.selectedIndex].value;
self.location='index.php?fdate1=' + val ;
}
</script>

Now put this in your first date element:
<select name="facctnum" onchange="reload(this.form)" >

Now put this in your form page at the top somewhere so when it loads, it will grab the value:
if ((!isset($_POST['submit'])) && (!empty($_GET['date1'])))
{
$date1=$_GET['date1'];
unset($_GET['date1']);
}

Finally, you can use the code i posted originally where $date1 has been retrieved in the GET.

Hope thats not too confusing:)
 

Naval Kishore Singal on 12 Jan 2012 08:19 reply

Hello Sir,

Javascript calendar is also not working when uploaded online. Any solution for that.
Please check.http://tauruslive.in/fdcalc/index.php.

Another thing I was also asked to asked date_default_timezone_set(''); in the code to make the calendar work. And it starts working when added date_default_timezone_set('Asia/Calcutta'); my timezone.

Naval Kishore Singal on 12 Jan 2012 08:24 reply

Sir, I also read to use datetime() instead of date() in php 5.3 and recently issued version 5.3.9 on jan10,2012. Please check if applicable for 2038 issue.
 

Michael on 09 Jan 2012 14:49 reply

Just wanted to thank you so much for this code!
Works like a charm and great job!!

 

Naval Kishore on 06 Jan 2012 13:40 reply

Thanks for the great code. But there is a bug in the code somewhere. I am able to track that bug. Please help. The bug is that I am not able to select date more than 19-01-2038 when the range of selection was set from 1950 to 2050. Some problem in js file, I think so. Please help.

ciprianmp on 06 Jan 2012 14:36 reply

Just read and follow the 3rd threat below.
We are working on this already. It's a php server on 32bits systems limitation and we are looking for a solution to allow dates over 2038.
Naval Kishore Singal on 07 Jan 2012 01:35 reply

Sir I am using the Windows 7 64 Bit system.
yumino on 12 Jan 2012 08:54 reply

use var_dump(PHP_INT_SIZE === 8);

if true is printing, you are on 64bits server. But if your work on your localhost like me (with wamp, xamp, ...) maybe you are on 32 bits.
i explain what i'm saying :

Sometimes with local php interpretor, 64bits version of php is not or bad managing. So maybe you can fix this problem.

However if you on 64bits server, you can try to use the DateTime class.
 

Pedro Failla on 06 Jan 2012 12:34 reply

Hi, First of all great code.
Im trying to create a series of calendar in same page, so the name is a array like this:

<code>
$df="datafeito[".mysql_result($exame,$x,'cod')."]" ;
$myCalendar = new tc_calendar($df , true, false);
</code>

This works great, and the names of the calendars appears to be ok in font, like "datafeito[15]"; "datafeito[32]" ....

BUT, when I do:

<code>
$datafeito2 = $_REQUEST["datafeito"];
foreach ($datafeito2 as $key => $value){
echo "key=$key e date=$value<br>";
}
</code>

I got $key ok (an ID) and date Always came ="pt_BR", which is the selected Lang.

Someone can help?

 

JC on 05 Jan 2012 14:01 reply

I just had to drop you a message to say how refreshing it is to see a well developed and well documented php code project. It looks very flexible and refined.

I am looking forward to trying this in my latest project.

 

yumino on 05 Jan 2012 09:06 reply

Great script, but he has a bug. when you put this :

require_once('./calendar/tc_calendar.php');
$myCalendar = new tc_calendar("test", true, false);
$myCalendar->setIcon("calendar/images/iconCalendar.gif");
$myCalendar->setDate(date('d'), date('m'), date('Y'));
$myCalendar->setPath("calendar/");
$myCalendar->setYearInterval(2000, 2100);
$myCalendar->dateAllow('2008-05-13', '2100-03-01');
$myCalendar->setDateFormat('j F Y');
$myCalendar->setAlignment('left', 'bottom');
$myCalendar->setSpecificDate(array("2011-04-01", "2011-04-04", "2011-12-25"), 0, 'year');
$myCalendar->setSpecificDate(array("2011-04-10", "2011-04-14"), 0, 'month');
$myCalendar->setSpecificDate(array("2011-06-01"), 0, '');
$myCalendar->writeScript();
}

and you try to select a year greater than 2037, you calandar is not working for an unknow reason. did you have any idea about it ?

TJ on 05 Jan 2012 09:31 reply

That's right.

Thanks for reporting this :)
yumino on 06 Jan 2012 04:16 reply

i don't know if you have already found the solution, but i have an idea about the origin of the problem. it's just a suggestion : if you call functions that use date in second since 1970, the problem may become that in 2038, sum of secondes is greater than integer limit (2147483647).

i can't try this assumption, but i think if could be the origin of the problem.

i hope it can help you

can you tell me when you fixed this problem plz ? :)
TJ on 06 Jan 2012 04:39 reply

yes the problem came from that reason and this calendar is based on many php date functions such as strtotime and date('W'), so it is hard to avoid this problem. The easiest way for now is to limit the year upto 2037. No solution yet :(
yumino on 06 Jan 2012 05:23 reply

maybe last version of php is able to manage this problematic. What do you think about it ?
yumino on 06 Jan 2012 05:29 reply

here you are some solution about it

http://stackoverflow.com/questions/5319710/accessing-dates-in-php-beyond-2038
TJ on 06 Jan 2012 05:32 reply

thanks for the information. I will check it when have time but not soon because I'm really busy these days. :(
yumino on 06 Jan 2012 05:43 reply

ok ok. Me too i will check it this afternoon. i will notify to you if i fixed this problem in the calandar
Naval Kishore Singal on 07 Jan 2012 01:41 reply

Please do mail me the solution, if you are able to fix it. My email id is naval_singla@sify.com. I will also trying to fix it. If fixed let you know.
yumino on 12 Jan 2012 05:35 reply

Sorry if i answered to you after one week, but i'm working in a part-time internship :x.

So, i will try to fix it today and tomorrow, i will notify to you by mail if i find the solution
TJ on 12 Jan 2012 08:24 reply

Hi, I got some idea but don't have time to try yet :(

Still got a heavy work load.
yumino on 12 Jan 2012 09:01 reply

hi,

I can't fix this problem on my machine because i work with wamp 64bits. However after some research, i found that php 64bits is not managing in localhost.

Futhermore, my online server is 32bits, so i'm trapped :x. I can't help you sorry :(
 

Matt Ernet on 03 Jan 2012 18:56 reply

Excellent script, thank you so much for providing this source for free! Everything works great & functionality is easy to extend. We added an area in our admin to allow admins to block out dates.

I would really like to see the removal of deprecated HTML attributes in some of the code in the future. It would be nice if the calendar would validate HTML 5 smoothly. I understand the complexities of maintaining x-browser compatibility however :-/

Great work and thank you again for the wonderful contribution & hard work!

a link to one of our implementations---
http://psp.thesocialfirm.com/book-it

 

Robert on 30 Dec 2011 15:24 reply

Great script but i am unable to get the set specific dates to work.

For instance i have all sundays disabled but i would like to enable 1 sunday.

When i input the:

$myCalendar->setSpecificDate(array("2012-01-28"), 1, '');

it just makes all dates unusable.

Here is the code i have implemented.

$myCalendar = new tc_calendar("date2");
$myCalendar->setIcon("/images/iconCalendar.gif");
$myCalendar->setDate(date('d'), date('m'), date('Y'));
$myCalendar->setPath("/applications/controllers/");
$myCalendar->setYearInterval(2011, 2012);
$myCalendar->setSpecificDate(array("2012-01-28"), 1 , '');
$myCalendar->disabledDay("sun");
$myCalendar->writeScript();

 

Paulo Gonçalves on 30 Dec 2011 13:23 reply

GREAT !!!!

Works very well

 

mirko1980 on 29 Dec 2011 14:51 reply

Hi,
this code is fantastic! I'm using the italian version and it works perfectly!
Just one question: do you know how can I move the calendar icon on the left (with text date on the right)?
Thank you very much!!!

ciprianmp on 29 Dec 2011 15:19 reply

Assuming that you're using the latest localized version, you need to open file tc_calendar.php and move the entire block from lines 340-344 before line 316.

echo(" <a href=\"javascript:toggleCalendar('".$this->objname."', ".$this->auto_hide.", ".$this->auto_hide_time.");\">");
if(is_file($this->icon)){
echo("<img src=\"".$this->icon."\" id=\"tcbtn_".$this->objname."\" name=\"tcbtn_".$this->objname."\" border=\"0\" align=\"absmiddle\" />");
}else echo($this->txt);
echo("</a>");
 

Alex on 26 Dec 2011 00:49 reply

Hello,

Thanks for the calendar script. It is working fine. I just have one doubt. I want to enable date field only for certain conditions (values in status field). By default I want to keep it disabled and want to do it using Javascript. Is it possible to access date1 using document.getElementById and keep the selection disabled/enabled?

Thanks in Advance.

 

zhongmengkai on 24 Dec 2011 18:47 reply

I am trying to use the "Date Pair Example" but when I try it I get a fatal error message saying. "Fatal error: Cannot instantiate non-existent class: tc_calendar in ...". Can any one please help me with this. I am still new to this and I really don't know what this error is.

zhongmengkai on 24 Dec 2011 18:49 reply

Oh and it is on the line for "$myCalendar = new tc_calendar("startdate", true, false); "
 

Mike on 18 Dec 2011 23:35 reply

Works great. Thanks. I just have one question I can't figure out.

I was previously using a textfield to enter the date in YYYY-MM-DD. When updating existing data, I pre-populated the textfield with the data already found in the database. I did this like this...

<input type="Text" name="birthdate" value="<?php echo $myrow["birthdate"] ?>">

This way, I wouldn't need to add this info again since (unless I changed it) the same data fir for that field would just be resubmitted again.

But I can't figure out how to do this one last, yet very important step using this script. How do I use the setDate function to set the starting date to what is already in the database? Specifically, how is this done since the database datestamp is YYYY-MM-DD but the setDate function of this script is in the format of DD, MM, YYYY? Can this be done?

Mike on 27 Dec 2011 20:48 reply

Can this be done? Can the date be pre-populated with the value already in the database?
Mike on 29 Dec 2011 20:17 reply

???
Mike on 31 Dec 2011 16:04 reply

PLEASE let me know if this is possible.The script works great as a single-directional input method but can it not be used for UPDATING existing dates in a database? I'd really like to keep using this script and not search for a new solution.
ciprianmp on 31 Dec 2011 16:12 reply

Please use the search box on top of the reviews... look for the words database or sql. We answered several times so far.
Besides... in 49 minutes here is midnight of New Year's Eve! Happy New Year 2012!
Let's PARTY!!!
 

Mathew on 18 Dec 2011 16:49 reply

Hi, Thank you very much for the wonderful script, It worked great, but got just one issue, I need to place more then one calenders in my page, I did just by pasting it again and again, but, when I click on any other calender icon, only the 1st one got popup, can you tell me how those all can be active?

Thanks

 
See all reviews 1 2 3 4 5 6 7 8 9 10 Next»
Write a review
Rating:
Your Message:
Name:
Email:
(optional)
(Your email that entered here will not show anywhere on website and will use only reference when someone reply your post)
  I want to receive a copy of email on this post (your email is needed)
 
Code:
 

Search this site