Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.