Jump to content

[SOLVED] Input date


aashcool198

Recommended Posts

As I see it, there are several options.  I know of several javascript scripts that popup and let you choose the date.  Or could just use a textfield and put the requested format next to it (like mm/dd/yy).

 

When you process that with the php script, you will want to format the date accordingly.  Using $date = strtotime($_POST['date']) and then take the date("n/j/Y",$date) will give you a good format.  Then you just insert into the database.

Link to comment
https://forums.phpfreaks.com/topic/161508-solved-input-date/#findComment-852300
Share on other sites

i input date as:

<input type="date" name="date">

 

and retrieve it using

 

$date = strtotime($_POST['date']);

$deadline = date("n/j/Y",$date);

 

and add in database:

 

$add_deadline = "INSERT INTO goals_deadline (goal_id, deadline)

VALUES ('$goal_id','$deadline')";

$result = mysql_query ($add_deadline) or die(mysql_error());

 

 

But the date is not inserted in database.  echo $deadline;  is giving the correct value but it is not inserted in database while the $goal_id is being inserted every time.

 

Please Help!

 

 

Link to comment
https://forums.phpfreaks.com/topic/161508-solved-input-date/#findComment-852916
Share on other sites

There's no date type for input fields, use text instead:

 

<input type="text" name="date" />

 

And try inserting a date in the standard format instead (YYYY-MM-DD), your current format is not recognized by MySQL:

 

$date = strtotime($_POST['date']);
$deadline = date('Y-m-d', $date);

Link to comment
https://forums.phpfreaks.com/topic/161508-solved-input-date/#findComment-852921
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.