I have a table called projects, and I'm currently coding the "create a project" functionality that allows the administrator to create a new project and save it in the projects mysql table.

I have a slight problem though, I have two fields/inputs named start date and deadline date, what should I use to allow selection of these dates in the form?

Dani AI

Generated

A concise, practical approach: use an HTML5 date control for modern browsers, add a JavaScript datepicker as a fallback/UX enhancement, store dates in the database with the correct MySQL type, and always validate on the server.

As noted, create proper date/time columns in MySQL. If only a date is needed use DATE; if a time component is required use DATETIME (or TIMESTAMP when automatic timezone conversion is wanted — note TIMESTAMP is converted to/from the server/session time zone, while DATETIME stores the raw value). See the MySQL manual on date/time types: MySQL date and time types.

For the form, prefer the native control: <input type="date" name="start_date">. Native controls give mobile-friendly pickers and reduce parsing issues (see browser support notes on MDN: input type=date (MDN)). As suggested, add a JavaScript picker (jQuery UI datepicker or a modern lightweight alternative) as a graceful fallback: jQuery UI datepicker.

Server-side rules (PHP): parse and validate the incoming date with the DateTime API (for example, using DateTime::createFromFormat('Y-m-d', $input)), enforce deadline >= start_date, and use prepared statements to insert the normalized YYYY-MM-DD value into a DATE column. Client-side min/max attributes and JS checks improve UX but are not a substitute for server validation.

Cautions: store timezone information only when needed; avoid relying on client locale for storage format; and always normalize dates before comparing or saving. This combination yields good UX, clean storage, and robust validation.

Recommended Answers

All 3 Replies

Have you got some tables and fields set up
in mysql? With date fields?

$from_date= date(Y,M,D)//or whatever php date function u decide.
$to_date = date(Y,M,D)//or whatever php date, could be today for example. 
$from_date = $_REQUEST['day_one'];
$to_date = $_REQUEST['today'];

then you SELECT day one < = $from_date and > = $to_date WHERE this AND so on...

See the date function
on php.net http://nz.php.net/manual/en/function.date.php

Use javascript date picker, there are may opensource scripts are available for it, gooogle it and get any one them and implement it in your scripts, I suggest Jquery is one of the best date picker.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.