CincoPistolero Posted November 24, 2007 Share Posted November 24, 2007 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? Quote Link to comment https://forums.phpfreaks.com/topic/78653-working-with-dates/ Share on other sites More sharing options...
trq Posted November 24, 2007 Share Posted November 24, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/78653-working-with-dates/#findComment-397986 Share on other sites More sharing options...
CincoPistolero Posted November 24, 2007 Author Share Posted November 24, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/78653-working-with-dates/#findComment-397990 Share on other sites More sharing options...
PHP_PhREEEk Posted November 24, 2007 Share Posted November 24, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/78653-working-with-dates/#findComment-397992 Share on other sites More sharing options...
CincoPistolero Posted November 24, 2007 Author Share Posted November 24, 2007 Can you suggest any sites to get samples from? Quote Link to comment https://forums.phpfreaks.com/topic/78653-working-with-dates/#findComment-397998 Share on other sites More sharing options...
PHP_PhREEEk Posted November 24, 2007 Share Posted November 24, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/78653-working-with-dates/#findComment-398002 Share on other sites More sharing options...
worldofcarp Posted November 24, 2007 Share Posted November 24, 2007 This page has some ok documentation on dates in php: http://php-date.com/ Quote Link to comment https://forums.phpfreaks.com/topic/78653-working-with-dates/#findComment-398316 Share on other sites More sharing options...
CincoPistolero Posted November 25, 2007 Author Share Posted November 25, 2007 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? Quote Link to comment https://forums.phpfreaks.com/topic/78653-working-with-dates/#findComment-398527 Share on other sites More sharing options...
wsantos Posted November 25, 2007 Share Posted November 25, 2007 Save yourself the trouble...use this http://www.meanfreepath.com/javascript_calendar/livedemo.html Quote Link to comment https://forums.phpfreaks.com/topic/78653-working-with-dates/#findComment-398529 Share on other sites More sharing options...
CincoPistolero Posted November 25, 2007 Author Share Posted November 25, 2007 The Windows downloads on that site seem to be corrupted. Quote Link to comment https://forums.phpfreaks.com/topic/78653-working-with-dates/#findComment-398540 Share on other sites More sharing options...
~n[EO]n~ Posted November 25, 2007 Share Posted November 25, 2007 You can try this too. www.dynarch.com/projects/calendar Best and open-source Quote Link to comment https://forums.phpfreaks.com/topic/78653-working-with-dates/#findComment-398555 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.