Forum Moderators: coopster

Message Too Old, No Replies

how to insert a manually entered date

I want to create a date record in mysql that is "useable" by mysql

         

andylarks

3:17 pm on Jan 22, 2004 (gmt 0)

10+ Year Member



I am trying to develop a project-management interface that allows a user to estimate when a job will start an finish. At some point, I then want to be able to query to find all jobs that fall between dateA and dateB.

My problem is that I have no idea how to take a user-entered date, and make it something that mysql can then use.

Can anyone help me?

Thanks :)

httpwebwitch

8:18 pm on Jan 22, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



MySql likes dates to be in the form:
YYYY-mm-dd hh:mm:ss

What you want is to avoid people typing in stuff like "01/02/01", "March 32, 1994", or even "next weekend". PHP's date functions might be good, but they're not THAT good.

So... Make the user choose date parts from select boxes, instead of a text input.

A good example of that is here, for entering a Date of Birth. Try to enter a bogus date. You can't! It even figures out leap years.

h**p://www.seekwellness.com/askanurse/form.htm

Alternately, you can have a friendly popup calendar that allows the user to choose the date. Those are nice.

With either method, some javascript is handy to know. My favourite method is to keep a "hidden" field in your form, and use javascript to construct it into the YYYY-mm-dd format. When the form is submitted, use the value of that hidden field in your SQL queries.

A good date selector is an important part of a developer's arsenal. Sticky-note me off-list and I'll lend you a few scripts to do exactly what you want.