my messages on the right please (i)


Like many coders, I have a code snippets that I use all the time. Many are attached to keyboard shortcuts, but sometimes the snippet involves more that a line or two, and it's useful to have somewhere to store these.


Examples here:,js,output

Notes to self: Don't forget the 'ui' bit in the field div!

Add 'calendar' as a class to the form, and 'dateselector' or similar to the field div, and it should just work.

Match the format of the default value using F d, Y

Parse the incoming date using date("Y-m-d", strtotime(posted_value));

More on handling the posted date...

if (isset($_POST["date_as_string"])) {
	if (isset($_POST["time_as_string"])) {
		$date_as_date=date("Y-m-d H:i:s", strtotime(trim($_POST["date_as_string"]." ".$_POST["time_as_string"])));
	else {
		$date_as_date=date("Y-m-d", strtotime(trim($_POST["date_as_string"])));
else { $date_as_date=date("Y-m-d"); }

$date_formated_for_calendar_form=date("F j, Y", strtotime($date));
$datetime_formated_for_calendar_form=date("F j, Y H:i A", strtotime($date));
When including via an Ajax style call, the JS needs to be included too, e.g.:
$(document).ready(function() {
	$('.date_selector').calendar({ type: 'date' });


This took a while to find:
	// time selector
	var minDateTime = new Date();
	var maxTime = new Date();
	minDateTime.setDate(minDateTime.getDate()) //    1
		type: 'time',
		minDate: minDateTime,
		maxDate: maxTime