Jump to content

Recommended Posts

I have a column in a table called testimonialDate. It is of type 'date'. When trying to modify a record, I can get it to display nicely on the modify page using:

 

$testDate = $testrow['testimonialDate'];
$testDate2 = strtotime($testDate);
$newdate=date("m-d-Y", $testDate2);

 

then <?=$newdate?>

 

However, when I change the displayed date and hit the modify button, it blanks out the testimonialDate column in the record selected.

 

I've found a lot of hints on the internet for displaying, but how do I send the info back up?

I'm also having issues trying to add a record. Typing in 3-3-2003 in text field results in 2003-3-20 in database.

 

Can I get some hints or a link to a good tutorial?

Link to comment
https://forums.phpfreaks.com/topic/78653-working-with-dates/
Share on other sites

However, when I change the displayed date and hit the modify button, it blanks out the testimonialDate column in the record selected.

 

Post the code which does this.

 

I'm also having issues trying to add a record. Typing in 3-3-2003 in text field results in 2003-3-20 in database.

 

Because that is how dates are stored in mysql.

Link to comment
https://forums.phpfreaks.com/topic/78653-working-with-dates/#findComment-397986
Share on other sites

some records in the database are currently set to 0000-00-00. When I use

<?php echo date('d-m-Y',strtotime($testrow['testimonialDate']))?>

 

I get 30-11-1999.

 

A correct date that gets displayed like 12-12-2007, and I change to 1-12-2007 gets put in the database as 2001-12-20. Not even the same day.

 

Here is my update statement:

<?php 
$query2 = "SELECT * FROM testimonial WHERE testimonialID='$testimonialID' ";
$result2 = mysql_query($query2) or die ("Error in query: $query2. " . mysql_error());
$row2= mysql_fetch_array($result2);
/* extract($row2); */
?>
<?php
$query = "UPDATE testimonial SET firstName='$firstName',lastName='$lastName',title='$title',testimonialDate='$testimonialDate',audioLink='$audioLink',videoLink='$videoLink',active='$active' WHERE testimonialID='$testimonialID' ";
$result = mysql_query($query) or die ("Error in query: $query. " . mysql_error());
?>

 

I'd like to know how to keep it from storing an incorrect date.

Link to comment
https://forums.phpfreaks.com/topic/78653-working-with-dates/#findComment-397990
Share on other sites

Store timestamps as UNIX and save yourself a ton of code and headache, really...

 

Set your fields that hold timestamps as INT(11). Insert, Update, or Fetch as UNIX timestamps.

 

Use PHP to format however you want when sent to the browser.

 

Save yourself time, overhead coding, and move on to something else = )

 

PhREEEk

Link to comment
https://forums.phpfreaks.com/topic/78653-working-with-dates/#findComment-397992
Share on other sites

Well php.net (http://us3.php.net/manual/en/function.time.php) comes to mind to start with. Make sure and browse through the comments to the article. There's a lot of cool things there, and you can gain a lot of quick knowledge looking through quick 'n dirty code snippets.

 

Then onto http://us3.php.net/manual/en/function.date.php to help you format, using the UNIX stamp as the input timestamp parameter.

 

After that, you'll need to let us know how you intend on using the timestamp. We can then give you snippets directly related to your need.

 

PhREEEk

Link to comment
https://forums.phpfreaks.com/topic/78653-working-with-dates/#findComment-398002
Share on other sites

All I want to be able to do is allow my clients to add dates for testimonials in m-d-yyyy format. And also have a modify page that displays it in mm-dd-yyyy format that they can then change and upload to the mySql DB. I don't care what methods it takes to display it that way and I don't care what sql formating I need to do to put it into the mySql db correctly. I just need some samples that work. I tried playing with the Unix Timestamp and couldn't get anything to load. I can get the date to pull from the db and display correctly, but when editing. mySql converts it incorrectly, so I'm using the wrong mySql formating.

 

If I have a date in mm-dd-yyyy in a <input type=text> what do I put in the SQL in my insert or update statement to get it to load to mySql as yyyy-mm-dd?

Link to comment
https://forums.phpfreaks.com/topic/78653-working-with-dates/#findComment-398527
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.