Pedro Graca wrote:[color=blue]
> Dominique Javet wrote:[color=green]
>> I'm new to php and mysql and I use Dreamweaver MX 2004, so sorry for
>> this "newbie" question... I've found no answer in the forum ...
>> I've a date problem with my formular. In my mysql DB my filed "date"
>> in table "experience" is like this: Y-m-d (2002-07-23).
>> My fied`date` is date, NOT NULL with no default entry
>>
>> My form read well the date data depending the id, (pe. 30.02.2003),
>> but when I submit a new date, I receive as result in the form
>> "30.11.1999" and my DB field I've now "0000-00-00"....
>>
>> I don't know how to correct this... I've lost several hours and I
>> think it's simple...
>> I will appreciate any suggestion and help.[/color]
>
> MySQL is dumb when it comes to dates!
> PHP is a little more intelligent but it doesn't compare to human
> ingenuity.
>
> So, you have to transform whatever the user typed, first into
> something
> PHP understand, and ultimately to something MySQL understands.
>
> I'd go about that by isolating the day, month, and year from the
> input;
> then dealing with them appropriately.
>
> If your users are always inserting dates as "dd.mm.yyyy" do
>
>
> $input = "30.02.2003";
>
> $input_day = (int)substr($input, 0, 2); // 30
> $input_month = (int)substr($input, 3, 2); // 2
> $input_year = (int)substr($input, 6, 4); // 2003
> if (checkdate($input_month, $input_day, $input_year)) {
> // date valid
> } else {
> // date invalid (the actual $input above will be invalid)
> }
>
>
> strtotime() accepts a whole lot of formats, but not the one you're
> using
http://www.php.net/strtotime
>
> and follow the link there to "Date Input Formats".
>
>
> Happy Coding :)[/color]
I would not use substr on that... For example, what if I put in today's
date? 1.5.04 - it will take the day as 1. the month as .0 and the year will
get nothing. use explode.
www.php.net/explode