Calendar with select box

I have an events calendar, which stores events in a mysql database by timestamps. (1226469600 = 12 nov 2008)

Now I need a second calendar which checks the database for events when a user picks a date through 3 select boxes. 3 select boxes with day, month and year. When the select boxes are set, a result will show at the bottom. (no datepickers, I need 3 select boxes!)
Is there a possibility to return an error when the user picks a date that doesn't exist?
How do I check the timestamp from these 3 boxes and return the result at the bottom?

Any ideas?
LVL 2
Hori76Asked:
Who is Participating?
 
Roger BaklundConnect With a Mentor Commented:
Use mktime() to calculate the timestamp, and then use date('Y-m-d') to check that the date was valid.

mktime() will accept invalid dates and transform it to a valid date. That's why you must use date() to check if the calculated date is the same as provided by the user. Remember to use two digits in the select dropdowns, i.e. 01, 02, 03 and so on.
<?php
 
$d = $_POST['day'];
$m = $_POST['month'];
$Y = $_POST['year'];
 
$date = mktime(0,0,0,$m,$d,$Y);
if(date('Y-m-d',$date)!="$Y-$m-$d") 
  echo 'Invalid date!';
 
?>

Open in new window

0
 
jausionsCommented:
Use the PHP checkdate() function [1] to validate a date.

[1] http://www.php.net/manual/en/function.checkdate.php
0
 
ovi_mihaiCommented:
i supose you want a javascript solution..
you can put a javascript on the submit button or on the select boxes

something like

var date1 = document.form.select1.value + "/" + ocument.form.select2.value + "/" +ocument.form.select3.value ;
var ret = isDate(date1, "d/m/Y"); //for 20/02/2008

rename date.js.txt in date.js
date.js.txt
0
 
Hori76Author Commented:
Thanks! This is exactly what i needed!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.