Unprepared for PHP Posted January 17, 2007 Share Posted January 17, 2007 Hi,I've tried googling around to find the answer to what I imagine is a fairly easy question, but nothing seems to have worked so far.I'm running Apache, PHP and Access (mySQL didn't install correctly for some reason.)In my Access DB, I have date fields, with various data in them, displaying in Access as:e.g.: 31 March 1985When I pull that out of the database by PHP, it displays it as:e.g.: 1985-03-31 00:00:00Someone suggested doing echo (date("j M Y", strtotime('dteDate'))); - but this just outputs 01 Jan 1970 to the screen.I'm also having a similar problem with times, with DB contents being:e.g.: 00:13:13... but displaying on screen as:e.g.: 1899-12-30 00:13:13I'd like to display both of these in the format they exist in within the DB. If anyone can help I'd really appreciate it.Cheers! Quote Link to comment https://forums.phpfreaks.com/topic/34491-newbie-question-on-date-formatting/ Share on other sites More sharing options...
dgiberson Posted January 17, 2007 Share Posted January 17, 2007 It depends on how you store the information in the database. Check the design view of the table to see how the data is stored, it sounds like you are storing the date in a Medium Date format. Change it to general date... essentially becomes a timestamp field, then you can use the date("<format here>", $date). Quote Link to comment https://forums.phpfreaks.com/topic/34491-newbie-question-on-date-formatting/#findComment-162467 Share on other sites More sharing options...
Unprepared for PHP Posted January 17, 2007 Author Share Posted January 17, 2007 Thanks for this.I have changed it to General Date, (and General Time for the second point). No change to the data displayed on screen yet. Quote Link to comment https://forums.phpfreaks.com/topic/34491-newbie-question-on-date-formatting/#findComment-162471 Share on other sites More sharing options...
dgiberson Posted January 17, 2007 Share Posted January 17, 2007 Is the date in Access still showing as 1-Jan-07? Quote Link to comment https://forums.phpfreaks.com/topic/34491-newbie-question-on-date-formatting/#findComment-162476 Share on other sites More sharing options...
Unprepared for PHP Posted January 17, 2007 Author Share Posted January 17, 2007 It now displays in Access as 31/03/1985 rather than 31 March 1985 as before. It still displays on-screen as 1985-03-31 00:00:00.Time continues to display in Access as 00:13:13, but displays on-screen as 1899-12-30 00:13:13.I am trying to get them to display as 31 March 1985 and 00:13:13.Cheers. Quote Link to comment https://forums.phpfreaks.com/topic/34491-newbie-question-on-date-formatting/#findComment-162477 Share on other sites More sharing options...
dgiberson Posted January 17, 2007 Share Posted January 17, 2007 So i take it, that you are having to different columns then? If you only require a single date/time i.e. 1/16/2007 00:13:13 store all that information in one field. then you can just format the field as you desire use: http://ca3.php.net/manual/en/function.date.php as a reference. Quote Link to comment https://forums.phpfreaks.com/topic/34491-newbie-question-on-date-formatting/#findComment-162481 Share on other sites More sharing options...
Unprepared for PHP Posted January 17, 2007 Author Share Posted January 17, 2007 Thanks. I've seen this link before when I was originally investigating it, but I am having difficulty understanding how to pass the variable into the expression, as all the examples seem to refer to formatting the current date/time. Quote Link to comment https://forums.phpfreaks.com/topic/34491-newbie-question-on-date-formatting/#findComment-162483 Share on other sites More sharing options...
dgiberson Posted January 17, 2007 Share Posted January 17, 2007 $date = query field from database.echo date("%y-%m-%d", $date); Quote Link to comment https://forums.phpfreaks.com/topic/34491-newbie-question-on-date-formatting/#findComment-162493 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.