Re: Date formatting Question (Beginner)

From: Date: Fri, 09 Jun 2000 13:58:54 +0000
Subject: Re: Date formatting Question (Beginner)
References: 1  Groups: php.db 
Request: Send a blank email to php-db+get-287@lists.php.net to get a copy of this message
Paul, The date returned by MySQL is not a timestamp value which the PHP date function requires. For me, I just wrote a quick function that converted the date returned by MySQL into a timestamp value, here it is: //input: a date of the form yyyy-mm-dd (returned from a mysql db date field) //output: the inputed date converted to a Unix timestamp format -- this format is required to use the php date/time functions function TimeStampenize($str_date) { $year = strtok($str_date, "-"); $month = strtok("-"); $day = strtok("-"); return mktime(0,0,0, $month, $day, $year); } This just uses the strtok function. I'm guessing there might be a better way to go about this, but for me this was my quick solution to the problem. Hope this helps! Sarah -- Sarah Kerr Bellanet International Secretariat http://www.bellanet.org 613-236-6163 ext. 2192 Paul O' Connor wrote: > > Hi, > > I've a date stored in a MySQL table. > When retrieving this date from the DB, I want to output this date in day, > Month Name, Year format. > > I've tried numerous variants of the following code: > > $date = $row["task_date"]; > print (date ("d F Y", $date)); > > However, I keep getting - 1 January 1970. > > The date in the DB is ok as > echo $date produces 2000-06-06. > > Regards, > Paul. > > -- > PHP Database Mailing List (http://www.php.net/) > To unsubscribe, e-mail: php-db-unsubscribe@lists.php.net > For additional commands, e-mail: php-db-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net

« previous php.db (#287) next »