| | |||||
| ||||||||
| Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics. |
![]() |
| | LinkBack | Thread Tools |
| | THREAD STARTER #1 (permalink) |
| NamePros Regular Join Date: Aug 2003 Location: England
Posts: 934
![]() ![]() ![]() ![]() ![]() | |
| | |
| | #2 (permalink) |
| NamePros Regular Join Date: Jul 2007
Posts: 323
![]() ![]() ![]() ![]() ![]() ![]() ![]() | If you're going to store your dates in the format YYYY-MM-DD you should probably use the date type instead of varchar. You'll find that you'll run into all sorts of problems using varchar if you're trying to query on those dates. Also, depending on what type of data you're storing in this table, you may also want to think about using the datetime type, which will save the full date and time in the format YYYY-MM-DD HH:MM:SS. |
| | |
| | THREAD STARTER #3 (permalink) |
| NamePros Regular Join Date: Aug 2003 Location: England
Posts: 934
![]() ![]() ![]() ![]() ![]() | If I set the field to 'date' type, how should my sql statement look? ---------- Post added at 05:11 PM ---------- Previous post was at 05:05 PM ---------- Because, I have just changed field type to 'datetime' And used the following code: PHP Code: I want it to be displayed as YYYY-MM-DD HH:MM:SS but as you can see its put it in the wrong order? |
| | |
| | #6 (permalink) |
| NamePros Regular Join Date: Jul 2007
Posts: 323
![]() ![]() ![]() ![]() ![]() ![]() ![]() | For your question about datetime, try using the following format for your php date function - "Y-m-d H:i:s" (capital Y and H). In other words, use this: Code: $datestamp=date("Y-m-d H:i:s");
$sql="INSERT INTO $tbl_name(itpname, detail, author, externalurl, datetime)VALUES('$itpname', '$detail', '$author', '$externalurl', '$datestamp')";
Last edited by demaxxus; 11-02-2009 at 09:30 AM.
|
| | |
| | #10 (permalink) |
| NamePros Regular Join Date: Jul 2007
Posts: 323
![]() ![]() ![]() ![]() ![]() ![]() ![]() | That's really bizarre, it should be working. Try narrowing it down first... Replace: Code: $datestamp=date("Y-m-d H:i:s"); ????: NamePros.com http://www.namepros.com/showthread.php?t=620615 Code: $datestamp=date("Y-m-d H:i:s");
echo $datestamp;
exit; |
| | |
| | #12 (permalink) |
| NamePros Regular Join Date: Jul 2007
Posts: 323
![]() ![]() ![]() ![]() ![]() ![]() ![]() | Try the same with the insert statement. Code: $sql="INSERT INTO $tbl_name(itpname, detail, author, externalurl, datetime) VALUES ('$itpname', '$detail', '$author', '$externalurl', '$datestamp')";
echo $sql;
exit; |
| | |
| | #14 (permalink) |
| Domains my Dominion Join Date: Aug 2005 Location: Web 1.0
Posts: 9,963
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | Instead of formatting the date in PHP you can also do it with mySQL using the DATE_FORMAT function.
__________________ NameNewsletter.com - free lists of available domain names ZoneFiles.net (beta) - ccTLD and gTLD droplists |
| | |
| | #15 (permalink) |
| Senior Member Join Date: Jul 2005 Location: NJ
Posts: 1,219
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | i believe the mysql NOW() function also does the same thing to get datetime. i personally always just keep it in terms of epoch time and then use php functions like date and mktime to go back and forth between epoch and readable time. it's MUCH easier to do computations with epoch time, so if you'll be doing things like time between datetimes etc, i'd suggest looking into it.
__________________ Hacksar.com - Your source for random computer tips and tricks! MySiteMemberships.com - Keep track of your site registration information! Like my post? Rep is appreciated! |
| | |