| Forum Home | ||||
| Press F1 | ||||
| Thread ID: 52369 | 2004-12-17 07:12:00 | PHP MYSQL insert Date | Morgenmuffel (187) | Press F1 |
| Post ID | Timestamp | Content | User | ||
| 304579 | 2004-12-17 07:12:00 | Greetings all I am having a major brain fart I am writing an online database management system, I have a table called "job" and every time I enter a new record I want one of the fields (called date_entered)to have that days date (should be simple). The problem is I want to be able to read this date out in a human readable form (on to a webpage), ie Friday 17th December 2004, or 17/12/2004 the field type is date '0000-00-00' word of warning version of mysql i am using is 4.0.22 and php is 4.3.9 also for another field enter date in human readable form (probably not too difficult) and convert it to to the Date format I have got very lost and confused using both the php and mysql manuals as apparently a lot of things have changed when mysql became v4.1 and these things don't work the version i am using, I realise this is probably patently simple but my brain is fried, basically all the solutions i have seen seem to overcomplicate what i believe should be a relatively simple bit of script Any help would be much appreciated Thanks nigel |
Morgenmuffel (187) | ||
| 304580 | 2004-12-17 07:46:00 | Insert the date in standard DB format, as it's only inserting a bog standard date stamp it doesn't matter to the end user. When calling the date from the database do: SELECT field1,field2,field9,DATE_FORMAT(timefield,'%Y %D %M %h:%i:%s %x') AS data FROM tablename; Then reference the timefield as "data" or whatever you wish to call it. Pretty sure the syntax is right. Or use this: Link (www.geekpedia.com) |
ninja (1671) | ||
| 304581 | 2004-12-17 07:50:00 | Thanks ninja I'll try that tomorrow morning CSI s on and my brains jelly thanks |
Morgenmuffel (187) | ||
| 304582 | 2004-12-17 21:49:00 | I have joke_date=CURDATE() on one of my pages, so you don't have to type in the date. That turns out as 2004-12-14 which is YYYY-MM-DD, which can be a bit confusing. |
mejobloggs (264) | ||
| 304583 | 2004-12-18 02:17:00 | YYYY-MM-DD confusing? No. It's logical and essential. Try sorting records by date if they have the weird and wonderful "human friendly" formats. Even without the US months-first idiocy, the lack of leading zeros for days and months gives unusable results. | Graham L (2) | ||
| 304584 | 2004-12-18 02:43:00 | oh, righty, I stand corrected. I guess its all personal preferance. |
mejobloggs (264) | ||
| 304585 | 2004-12-18 02:47:00 | There will be room for personal preference in the way you show dates in output, but it's essential to have the stored dates so they can be sorted. | Graham L (2) | ||
| 304586 | 2004-12-18 03:18:00 | ah, true, I see what you mean now. | mejobloggs (264) | ||
| 1 | |||||