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 :
Select
  • 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 = "2013-05-20";
$date4_default = "2013-05-26";

$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 (41.13 KB.)
Version 3.69 (21 May 2013)

What's new

Version 3.69

  • [Added] Use php DateTime class to handle date and also support for year 2038 and later (limited to php version >= 5.3.0)
  • [Fixed] Check valid of Today date if it is in range of enabled date
  • Minor bug fixed and adjustment

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 :

john on 16 May 2013 05:50 reply

how to set date picker style in codeigniter

 

Bhushan Karna on 16 May 2013 04:33 reply

I am unable to create date picker calander in my PHP coding. Please get me some help. I will be
very kind to you.

ciprianmp on 16 May 2013 04:58 reply

Ok, but to help you we need more info. What did you do, what is the error, which version you downloaded (localized or english) and so on.
Also provide a link to your page.

You can contact me directly to my email address.
 

meg on 15 May 2013 20:43 reply

i do not get the drop-down box. I just get a small box. Using localhost in chrome

ciprianmp on 16 May 2013 04:59 reply

A link will explain better...
 

rhk on 10 May 2013 19:26 reply

the best datepicker until 11 may 2013.

 

Robert on 08 May 2013 20:43 reply

Hello, there!

I want to ask something, when I use this script:
<?php
$theDate = isset($_REQUEST["date1"]) ? $_REQUEST["date1"] : "";
?>

How can i get the day value?What should I change to get the day value?

Thank you... :D

 

John Romaine on 05 May 2013 03:39 reply

Why are some of the dates crossed out? For some reason certain days are unavailable??????

 

jonard on 05 May 2013 01:47 reply

Hi, I would like to ask something, i have a form with this datepicker, i want to submit the result of the datepicker to its own page, my problem is i want the date(setdate()) to be the one i selected. but the problem is everytime my page reloads the defauls setdate always appear.

 

Ray Wilson on 02 May 2013 06:48 reply

I am setting up a members database and using date picker to add dates(e.g. dob, start date, end date) to my database - all working ok. Some of the date fields are not available at time of form submit so I have created an update form for these dates but unable to know how to display the dates using date picker from the database and update missing date fields. If I set $myCalendar->setDate(0,0,0); but need to set to e.g. field $row members ['dob'], otherwise overwrite dob to the SetDate. Can you please advise me hpw I do this?

 

adn on 24 Apr 2013 23:20 reply

how to get selected date in javascript without using form?

adn on 24 Apr 2013 23:37 reply

how to use $myCalendar->setOnChange("javascriptFunctionName()");
and get selected date ($myCalendar->getDate();)?

anyone?
thanks
 

Les Mizzell on 23 Apr 2013 11:25 reply

IE (of course) problem...

I've got a number of these set up and working exactly like I wish now, but ...

In all browsers, except IE, the picker stays open while you're selecting a month/year from the drop down at the top of the picker window, stays open while you're selecting a date, and remains open the set "delay" time as well, just like it should.

In IE, when you click the drop down, and if you don't pick a month/year quick, the picker closes.

I does stay open properly as long as the mouse is over the calendar portion. Seems only the month/year drop downs are the issue.

I've been trying to figure this out for a couple of days now. No luck.

Ideas please??

Thanks!

 

Vidar on 22 Apr 2013 14:30 reply

Hi! I've used this datepicker for some time now, and I'm very pleased with it. But now I'm developing a new site in Joomla, and I'm wondering how I can use this datepicker in Joomla? Anyone who could help me with this?

Regards, Vidar

 

sky on 16 Apr 2013 22:48 reply

Hi,

i would like to ask if there is a way to not reset the date in the date picker after i submit the form?

my code goes like this:

$start_cal = new tc_calendar("start", true, false);
$start_cal->setText("");
$start_cal->setDate(date('d')
, date('m')
, date('Y'));
$start_cal->setPath("calendar/");
$start_cal->setYearInterval(1980, 2030);
$start_cal->setAlignment('left', 'bottom');
$start_cal->setDatePair('start', 'end');
$start_cal->zindex = 100;
$start_cal->writeScript();

$end_cal = new tc_calendar("end", true, false);
$end_cal->setText("");
$end_cal->setDate(date('d')
, date('m')
, date('Y'));
$end_cal->setPath("calendar/");
$end_cal->setYearInterval(1980, 2030);
$end_cal->setAlignment('left', 'bottom');
$end_cal->setDatePair('start', 'end');
$start_cal->zindex = 100;
$end_cal->writeScript();

thank you very much.

 

Heinrich on 15 Apr 2013 06:11 reply

Hallo there,

this seems to be a great calendar. However, when I tried to integrate your calendar into my php script, it doesn't execute the javascript. So, what could be wrong ?

Your source code only works.

Best,

ciprianmp on 16 Apr 2013 14:10 reply

We need more explanations or a link to see what's wrong.
It could be a wrong setPath or who knows...
 

snowflake on 14 Apr 2013 05:10 reply

Brilliant code thanks.

I could be completely stupid here but I my disabledDay isn't working. I need it to only allow the user to select a Friday so I did the following:

<?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(2013, 2020);
$myCalendar->dateAllow('2013-04-01', '2015-03-01', false);
$myCalendar->startMonday(true);
$myCalendar->disabledDay("sat");
$myCalendar->disabledDay("sun");
$myCalendar->disabledDay("mon");
$myCalendar->disabledDay("tue");
$myCalendar->disabledDay("wed");
$myCalendar->disabledDay("thu");
$myCalendar->writeScript();
$myCalendar->getDate();
?>

I'm very new to php, so any help would be amazing - thankyou in advance.
Snowflake.

ciprianmp on 16 Apr 2013 14:17 reply

Using your exact code worked perfect for me.
Here's a fine sample, with your code:
http://ciprianmp.com/scripts/calendar/support/test_sf.php
 

johanes on 12 Apr 2013 12:49 reply

i have got 2013-04-12 when i used this one
$theDate = isset($_REQUEST["date1"]) ? $_REQUEST["date1"] : "";



if i want to make the date +30 days

what am i have to do

ciprianmp on 16 Apr 2013 14:32 reply

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

then:

$theDate = date("Y-m-d", strtotime("+30 days", strtotime($theDate)));
OR
$theDate = strftime("%Y-%m-%d", strtotime("+30 days", strtotime($theDate)));

To test:
echo $theDate;
 

Les Mizzell on 12 Apr 2013 09:11 reply

It would appear that adding a "setSpecificDate" parameter overrides the "setDate" parameter?
For the below, I can not get a set date to display in the calendar as long as "setSpecificDate" is set.

I'm using this in a form to edit records. I'm omitting dates that can't be chosen ( $rdates, which is a array ), which is working fine.
If I comment out the "setSpecificDate" line, then the proper set date from the if statement will display.

Is there a way around this?


$today = date("Y-m-d");

$start=''.$gtnote['startdate'].'';
$date_array=explode ("-",$start);
$syear=$date_array[0];
$smonth=$date_array[1];
$sday=$date_array[2];

$myCalendar = new tc_calendar("start_date", true, false);
$myCalendar->setIcon("calendar/images/iconCalendar.gif");
if ($gtnote['startdate'] != ''){
$myCalendar->setDate($sday, $smonth, $syear); }
else {
$myCalendar->setDate(date('d'), date('m'), date('Y')); }
$myCalendar->setPath("calendar/");
$myCalendar->setYearInterval(2012, 2030);
$myCalendar->dateAllow('2012-01-01', '2030-12-30');
$myCalendar->setDateFormat('j F Y');
$myCalendar->setAlignment('left', 'bottom');
$myCalendar->setSpecificDate($rdates, 0, '');
$myCalendar->setDatePair('start_date', 'end_date');
$myCalendar->writeScript();
$myCalendar->zindex = 999;

ciprianmp on 12 Apr 2013 09:49 reply

I wouldn't think so.
What's in the $rdates array? I suspect the setDate is included, so it can't be selected. You need another
elseif(in_array($gtnote['startdate'], $rdates)){
$myCalendar->setDate("00", "00", "0000"); }

Or do something else inside this conditional, like:
array_replace($rdates, $gtnote['startdate'], "");

It depends what you want to do and what data you have there...

Les Mizzell on 12 Apr 2013 10:16 reply

Ahhh ... yes, you are correct! An error in my logic!

Any date already picked is in the setSpecificDate array, so if you're editing a record, it can't be chosen again!

Obviously I need WAY more coffee than I've already had this morning.

Thanks!
 

Jonas on 10 Apr 2013 11:51 reply

I use this calendar on two places within my form. So I have Calendar nr1 and Calendar nr2. When I select a date in calendar nr1 I want Calendar nr2 to be updated with the same date.

Then if I want to change the date in Calendar nr2 I still want Calendar nr1 to have the same date.

Is there a way to do this? And if so, how do I do that?

The purpose is that most users want Calendar 2 to have the same date as Calendar 1, but there are occasions when a user want to change the date in Calendar 2, but Calendar 1 needs to stay the same.

ciprianmp on 11 Apr 2013 11:36 reply

There might be other solutions, but this is what I came up with:

After the <body> tag of your file, add this function:
<script language="javascript">
<!--
function myChanged(v){
var date_array = document.getElementById("Calendar1").value.split("-");
tc_submitDate(v, date_array[2], date_array[1], date_array[0]);
}
//-->
</script>

Note: if you already have a <script section, just add there the function itself:
function myChanged(v){
var date_array = document.getElementById("Calendar1").value.split("-");
tc_submitDate(v, date_array[2], date_array[1], date_array[0]);
}

Then, in the first calendar constructor add this line:
$myCalendar->setOnChange("myChanged('Calendar2')");

Replace "Calendar1" and "Calendar2" with the form names you given to your calendar forms (date3 or so). Let me know if it worked.
Jonas on 18 Apr 2013 16:07 reply

The solution worked very well. Thanks for the help!

I have two additional questions:

1) I send the values from the form in a mail and get a lot of info I don't need. For example:

date1: 2013-04-17
date1_dp: 1
date1_year_start: 1960
date1_year_end: 2015
date1_da1: 1366156800
date1_da2: 1425168000
etc...

The only value I want is "date1: 2013-04-17" (and of course "date2: 2013-04-17" since I'm using two calendars). Is there a way to disable all the other values, and keep them from being passed when submitting the form?

2) Is there a way I could set the calendar to being displayed to the right of the calendar icon instead of beneath it?


 

Carlos on 09 Apr 2013 15:31 reply

Hi, Ciprian

Your calendar is great, it's just what I needed!

I'm sort of new to php and html programming and my problem might seem trivial and more related to html forms than to your calendar. Anyway, here it goes: I'm trying to add the calendar to a form where there are other input fields (dropdown lists and texts), each with its label on the left. I would like to add a label (e.g., "date of compliance") to the left of the calendar, but if I add the code into my php/html page the way you explain above, the calendar always appears at the top of the form and I don't know how I can add the label. I'm using the DatePicker with no input box option. Hope you understand my issue and thanks in advance.

Carlos

ciprianmp on 09 Apr 2013 17:52 reply

Hi Carlos,
First of all, it's not my calendar :D
TJ is the main programmer of the class. I just adapted and released the localized version of his class (41 languages hehe). So all the credits go to TJ!

About your question, I had no issues including the class in my app form, so not sure what's wrong in your code. Is it a table that holds the class in that form? If so, that happens if the value is not put in a <td></td> cell tag.
Maybe I can have a link to take a look or better send me the file for a check up (ciprianmp at yahoo com).
Here is a demo of the calendar in a table:
http://ciprianmp.com/plus/ Use register link.

PS: Next time you post I recommend you add an email address so you get the notification of replies to your posts.
Carlos on 11 Apr 2013 07:39 reply

Hi Ciprian,

I followed your recommendation and it worked fine, and the internationalized feature was of great help. Actually, with the version that I first downloaded from this page it worked with the editable input text (3rd parameter true in the constructor) but it still didn't with the non-editable one. But with the version you sent me by e-mail it worked fine on both.

Thanks again!

Brad on 30 Apr 2013 13:31 reply

The problem here is that the calendar uses the echo command to immediately write to the browser. If you have not output any html yet, it will appear in the upper left corner since that the calendar script is being output first. I like to generate my entire page as a string first, then output all at once to the browser, so in this case it's not possible to use without changing the tc_calendar.php file to return a string in all the write functions vs simply echoing immediately. I'm going to try to modify the code locally to accommodate for this.
 

FRANK FARAZ on 04 Apr 2013 05:50 reply

Hi there,

Am getting warning like this:

date() [function.date]: It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'Australia/Perth' for 'WST/8.0/no DST' instead in /home/theholis/public_html/wp-content/plugins/appointment-calendar-premium/calendar/calendar_form.php on line 48

What should i do getting rid of this?

Need help please.

post me at: farazfrank777[at]gmail.com

 

@refvry on 03 Apr 2013 20:30 reply

thank you for the information

 

Ed on 03 Apr 2013 13:15 reply

Hi again, Trying to change the format from YYYY-MM-DD to DD-MM-YYYY. or any format come to that. I have tried:

$datum = strftime("%d %m %Y", strtotime($datum))

and/or

$myCalendar->setDateFormat('%d %m %Y');

but it when i echo the var i get year first format (ie nothing changed) and with strftime i get unexpected var.

Have also changed the allowed dates ($myCalendar->dateAllow) to GB format

If you need any more info just ask.
Where am i going wrong?

ciprianmp on 03 Apr 2013 15:12 reply

Hey again Ed,
I suppose you are using my localized version of the class, displaying the en_GB formats, right?
If so, I can't see why you would need to change the internal class date formats to UK, as that's just internal. Besides, we strongly recommend not to do so. The class needed to use a single format in it's private functions, in order to handle (select, extract, check aso) the dates in a universal way. To do so, the YYYY-MM-DD format it's the most common in both php functions and mysql field properties.

We as users can then easily and effectively play/handle the var in our pages, for display purposes only. Which you actually needed and try above.

Now I hope I came to your real question: how to change the var format in order to be used/displayed in your pages (not breaking the class internal format). Well, you've made the right start by using strftime. I don't know what you have before that line (although an ending ; is missing in your line), but you need to have this line in the header of the file:
$datum= isset($_POST["date1"]) ? $_POST["date1"] : "";
note: make sure you match date1 with your form name.

After this call, the $datum var shall not be undefined anymore, but actually containing the current date selected in your calendar form (in the standard YYYY-MM-DD format, of course).
So later on on the page, you can do whatever you wish with the var, including what you've tried:
$datum = strftime("%d %m %Y", strtotime($datum));
echo($datum);

That's it.

As for the setDateFormat, using the localized version of the class, you don't really need that function anymore (I recommend changing the format in the lang/calendar.en_GB.php file but it's just a choise), as the displaying format's are defined in the localized files per each language.
Still, if you ever need to change that displaying format by calling the setDateFormat(), you need to use the php date() formats, which differ from those you used (you used the strftime formats). Example:
$myCalendar->setDateFormat('d m Y');
note: without %. More samples at http://www.php.net/manual/en/function.date.php.

Let me know if I wasn't clear enough or if it doesn't work for you.
ciprianmp on 03 Apr 2013 15:20 reply

Small correction to match your need (I forgot you wanted dashes):
$myCalendar->setDateFormat('d-m-Y');

Try out this one too (just for showing of :p):
$myCalendar->setDateFormat('l, dS \of F Y');
(it is the date() equivalent for EN strftime() long date format)
Ed on 04 Apr 2013 05:20 reply

Hiya mate,

Fair enough, i have left in in YYYY-MM-DD format and changed it just before the echo with

$datum = date('d-m-Y', strtotime($_REQUEST['date1'] ? $_REQUEST['date1'] : ''));

- well pleased!

Just a note to anyone else viewing this, take note of where the double brackets are, i spent a little time getting unexpected ":" duh!

I hadn't actually named the form...?? but it still works, gotta say whatever you have done is pretty robust!

Cheers for your help!

Ed

 

johnny on 02 Apr 2013 11:23 reply

Hello,
I downloaded the zip and trying it out on my server and i do not get the drop-down box. I just get a small box. any ideas?

johnny on 02 Apr 2013 11:34 reply

I figured it out.
meg on 15 May 2013 20:42 reply

hey how did you fix it? i encounter the same thing
 

Niaa on 31 Mar 2013 21:33 reply

hi ciprianmp. i have a question. i have database table that stores the
name, departure date, return date, task, location

Now I'm trying to link my data to a calender so when I pick a date all the name, task and location are display in web page. Is there possibility to do so? any ideas?

i'm using calendar Fixed Display Style.
thanks in advance :)

ciprianmp on 01 Apr 2013 15:35 reply

It's possible and pretty easy.
It has been discussed here (it will take a while to load, so be patient):
http://www.triconsole.com/php/calendar_datepicker.php?alc=1#cmt819
If you can't find it, let me know.
Niaa on 01 Apr 2013 21:12 reply

Is it a message from WDjoe on 24 Dec 2010 14:53?
can you show me how to do this? where should i start? seriously i'm lost. pls help me.:(
ciprianmp on 02 Apr 2013 10:21 reply

Yes, follow that conversation to understand what to do.

PS: I sent you a private email, did you get it? (send me the file and I'll adjust it for you)
Niaa on 02 Apr 2013 19:31 reply

Yes. I already sent you the file.
 

Ed on 29 Mar 2013 12:53 reply

Awesome and very elegant. I can't get the calendar icon to appear at the moment, just shows "select" lol. odd. Good work ciprianmp, will be donating as soon as i get it all working.

ciprianmp on 29 Mar 2013 15:55 reply

Hi Ed, I'm glad you like it.
You need to add this line:
$myCalendar->setIcon("calendar/images/iconCalendar.gif");

PS: we're preparing a better release soon, so stay tuned!
Ed on 03 Apr 2013 11:59 reply

excellent! will do!
 

pixeldesign on 28 Mar 2013 00:51 reply

Work In Localhost but online give 500 internal server error please help

ciprianmp on 29 Mar 2013 15:57 reply

As soon as you get that error, go in your site cpanel (admin menu on the hosting site) and check the error log, then reply and paste here the 500 explanation related to the calendar. God knows what's there lol ;)
 

Niaa on 27 Mar 2013 02:38 reply

hello ciprianmp. pls help me. i want to display the date from my database to web page. but it didnt work. here my coding:

<table width=80% border='1' align="center" cellpadding='0' cellspacing='0' bordercolor="#333333" bgcolor="#FFFFFF">
<tr>
<th>TARIKH BERTOLAK DARI PEJABAT</th>
<th>TARIKH BALIK KE PEJABAT</th>
<th>TEMPAT BERTUGAS</th>
<th>TUGAS-TUGAS SEBENAR</th>
<th>JENIS KENDERAAN</th>
<th>NOMBOR FAIL</th>
</tr>

<?php
while($row = mysql_fetch_array($result))
{
?>
<tr>
<td><center><?=$row['$date3']?></center></td>
<td><center><?=$row['$date4']?></center></td>
<td><center><?=$row['tempat']?></center></td>
<td><center><?=$row['tugas']?></center></td>
<td><center><?=$row['kenderaan']?></center></td>
<td>&nbsp;&nbsp;&nbsp;</td>
</tr>

ciprianmp on 27 Mar 2013 11:07 reply

The code you osted doesn't show where the vars come from, but first mistake it this:
<td><center><?=$row[\'$date3\']?></center></td>
<td><center><?=$row[\'$date4\']?></center></td>
Change it to:
<td><center><?=$row[\'date3\']?></center></td>
<td><center><?=$row[\'date4\']?></center></td>
No $date3 as that is the name of the varaiable, not the var itself.
I hope it helps.
Niaa on 27 Mar 2013 19:55 reply

thankss. but it still not working.still display like this. pls help me.:(

Notice: Undefined index: date3 in D:\EasyPHP-12.1\www\SISTEM PEGERAKAN PDTCH\cetakprocess.php on line 78

Notice: Undefined index: date4 in D:\EasyPHP-12.1\www\SISTEM PEGERAKAN PDTCH\cetakprocess.php on line 79
ciprianmp on 28 Mar 2013 10:01 reply

I can't help you as you don't give us enough information.
Send me the file.
Niaa on 28 Mar 2013 21:44 reply

I already got the solution. i just replace date3 with the column number of table in my database

<td><center><?=$row[2]?></center></td>
<td><center><?=$row[3]?></center></td>

 

Claude Raines on 23 Mar 2013 14:26 reply

IE hangs / throws syntax error calendar.js, line1 character 1?

Script looks fine, and works fine on your site, any ideas?

ciprianmp on 25 Mar 2013 14:56 reply

What I can suggest is to check if the calendar.js file has some trailing spaces inside.
You can easily do that using Notepad++ then in Menu/Edit/Blank Operations/Trim Trailing Space.

If this doesn't fix it, try re-downloading and uploading again.
 

venkatesh on 23 Mar 2013 00:13 reply

Dear Friends,

i used DatePicker with no input box but i want no upper date select for current date
ie
current date > select date is not select ..,

correct way :

current date < select date is a correct ..,

is there any option this datepicker..,

thanks in advance..,

 

Stacy J on 21 Mar 2013 13:34 reply

I like this script, however I would like to format the date to MM DD YYYY instead of DD MM YYYY.

How to I do this?

 

Nicole on 19 Mar 2013 17:32 reply

I get this error when trying to use it (The problem is with the selectDay javascript function?):

Uncaught exception: TypeError: Cannot convert 'replace' to object
Error thrown at line 408, column 2 in <anonymous function: Date.prototype.format>(format) in http://localhost:8888/calendar_localized_368/calendar/calendar.js:
if (replace[curChar])
called from line 1, column 0 in javascript:selectDay('02');:
selectDay('02');

Help?

ciprianmp on 20 Mar 2013 17:18 reply

Nicole, I've never seen such an error, so right now I can't say where it comes from.
I have updated the function that throws that error, it might fix it for your server.
So please download again the localized version from the link above. Let me know if it works.

On the other hand, you shouldn't put the files in calendar_localized_368 - that was just the name of the archive.
Try to move entire "calendar" subfolder one level up. It could be a reason for other errors.
Also a link for testing would be helpful.
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