Calendar with select box

Posted on 2008-11-12
Last Modified: 2012-06-27
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?
Question by:Hori76
    LVL 11

    Expert Comment

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

    LVL 39

    Accepted Solution

    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.
    $d = $_POST['day'];
    $m = $_POST['month'];
    $Y = $_POST['year'];
    $date = mktime(0,0,0,$m,$d,$Y);
      echo 'Invalid date!';

    Open in new window

    LVL 3

    Expert Comment

    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
    LVL 2

    Author Closing Comment

    Thanks! This is exactly what i needed!

    Featured Post

    Why You Should Analyze Threat Actor TTPs

    After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

    Join & Write a Comment

    Suggested Solutions

    Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL ( several years ago, it seemed like now was a good time to updat…
    Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
    The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
    The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now