Jump to content

[SOLVED] date problem


shadiadiph

Recommended Posts

Hi guys on my form I have a date field which saves to sql

 

the problem I have is this

 

when the user inputs the date it is done in this format.

 

<tr>
<td id="t_date">Date </td>
<td><input name="date" type="text" class="textfield" value="<?=$tradedate?>"> 
enter date as (dd-mm-yyyy) </td>
</tr>

 

so the date is being entered for exmple 30-10-2009 when i do the sql insert it won't allow it because the date always says it saved as 0000-00-00?

 

$insertsql ="insert into tbltradedetails (date) values ('$date')";

Link to comment
https://forums.phpfreaks.com/topic/140990-solved-date-problem/
Share on other sites

The strtotime function does not understand a date in the form dd-mm-yyyy. It does understand mm-dd-yyyy and yyyy-mm-dd. You need to reformat the input:

<?php
$date = "30-10-2009";
list($mm,$dd,$yyyy) = explode('-',$date);
$newdate = $yyyy . '-' . $mm . '-' . $dd;
?>

 

Ken

Link to comment
https://forums.phpfreaks.com/topic/140990-solved-date-problem/#findComment-737934
Share on other sites

this seems to work

 

$date = explode("-","$tradedate");
$newdate = strftime("%Y-%m-%d",mktime(0,0,0,$date[1],$date[0],$date[2]));

 

if it helps someone in the future

 

in theory i guess when I call the data from the database i could use the same method to display it back as 15-01-2009 also

Link to comment
https://forums.phpfreaks.com/topic/140990-solved-date-problem/#findComment-738083
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.