Jump to content

[SOLVED] Updating a date with php and mysql?


lokie538

Recommended Posts

Hi,

 

I have a date that is shown in a text field on a form. Now im trying to update it, but im not sure how. In the text field on the form the date is shown in the format 2007/12/03 and to update it im just thinking that they can change the 2007 to 2008 or whatever. im using this script to update and the collum is in date format.

 

$query2 = "UPDATE studhpe1 SET Date_Enrolled= '{$_POST['date1']}' WHERE StudentID = '{$_POST['studentid']}'";
$result2 = mysqli_query($cxn,$query) or die ("Couldnt execute query.");

 

is there a way to update dates?? and how should I do it? I may have the whole wrong approach.

 

Thanks in advance,

Lokie538

Link to comment
Share on other sites

is the msql date field actually set to be a date/time field? or just a plain text field?

 

if its a specific date/time field then yes you need to insert the date/time in the correct format. if its just plaint text then you can insert whatever date.

 

Whats the error you get?

Link to comment
Share on other sites

The field is in the date format. not just a text field.

 

The date im trying to update is in the format y/m/d which is the format it is retreived as. When i use the code below all i get is "Couldnt execute query"

 

$query2 = "UPDATE table SET Date_Enrolled='" . $_POST[date1] . "' WHERE ID ='" . $_POST[tid] . "'";
$result2 = mysqli_query($cxn,$query2) or die ("Couldnt execute query2.");

 

Yeah i dunno why its not working, something to do with the wrong format?

Link to comment
Share on other sites

so how do i change the format? lol

 

lol indeed. You can't change the format of a date field, it's yyyy-mm-dd and that's it.

 

I suspect what you really want to concentrate on is how to convert some text format of 'date' as entered by a user (which makes the date format beyond your control - bad idea) and display the database information for date in some preferred 'friendly/local' format.

Link to comment
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.