Re: [PHP] Formatting timestamp date in MySQL
Hello, The column is set as date timestamp(8). A sample of date is 20020409 I use the PHP Date function to format it back to say 9th April 2002. $date_formated = date($date, 'S M Y' ); How about this; $date_formatted=date(jS M Y,mktime(0,0,0,substr($date,4,2),substr ($date,6,2),substr($date,0,4))); However I guess this is proper 4 U; $date_formatted=date(jS F Y,mktime(0,0,0,substr($date,4,2),substr ($date,6,2),substr($date,0,4))); Hiroshi Ayukawa http://hoover.ktplan.ne.jp/kaihatsu/php_en/index.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Formatting timestamp date in MySQL
There is a difference between MySQL's timestamp, and a UNIX timestamp. strtotime(); is a really valuable tool -- converting almost any English date description -- check out the manual for more info. Anyway, in this case, it is able to convert your MySQL date of 20020409 into a unix timestamp, which is the required format for date() formatting. In clear code: ? $date = 20020409; $date_unix = strtotime($date); $date_f = date('jS M Y',$date_unix); echo $date_f.BR; ? Although this can be condensed to: ? $date = 20020409; $date_f = date('jS M Y',strtotime($date)); echo $date_f.BR; ? or even just ? $date = 19770417; echo date('jS M Y',strtotime($date)); ? Check out: http://www.php.net/manual/en/function.date.php http://www.php.net/manual/en/function.strtotime.php for more info and date() formats. Note: I haven't done a heap of testing with strtodate() to ensure it's going to return what you expect, but I randomly tested 10 dates in your format between 1977 and 2002 without any problems. Justin French Creative Director http://Indent.com.au on 09/04/02 9:53 PM, nyon ([EMAIL PROTECTED]) wrote: Hi, I need to recall a date data in a MySQL database. The column is set as date timestamp(8). A sample of date is 20020409 I use the PHP Date function to format it back to say 9th April 2002. $date_formated = date($date, 'S M Y' ); However, it's still doesn't appear as formatted. Anyone mind sharing their code to do this? Nyon -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Formatting timestamp date in MySQL
Hello, I just started with php and I'm also trying to format mysql date -mm-dd into mm/dd/. I looked through some books and they describe the use of DATE_FORMAT to covert the dates. Is there any other way to format the date? Thanks Alex My script looks like this: $month_1 = ($date_month_1); $day_1 = ($date_day_1); $year_1 = ($date_year_1); $month_2 = ($date_month_2); $day_2 = ($date_day_2); $year_2 = ($date_year_2); $query = SELECT * FROM tablename where date = '$year_1-month_1-$day_1-' AND date = '$year_2-$month_2-$day_2'; $result = mysql_query($query); $num_results = mysql_num_rows($result); echo pNumber of records found: .$num_results./p; for ($i=0; $i $num_results; $i++) { $row = mysql_fetch_array($result); echo pstrong.($i+1).. ID: ; echo ($row[id]); echo /strongbrFirst name: ; echo ($row[fname]); echo brLast name: ; echo ($row[lname]); echo brDate: ; echo ($row[date]); Justin French [EMAIL PROTECTED] wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... There is a difference between MySQL's timestamp, and a UNIX timestamp. strtotime(); is a really valuable tool -- converting almost any English date description -- check out the manual for more info. Anyway, in this case, it is able to convert your MySQL date of 20020409 into a unix timestamp, which is the required format for date() formatting. In clear code: ? $date = 20020409; $date_unix = strtotime($date); $date_f = date('jS M Y',$date_unix); echo $date_f.BR; ? Although this can be condensed to: ? $date = 20020409; $date_f = date('jS M Y',strtotime($date)); echo $date_f.BR; ? or even just ? $date = 19770417; echo date('jS M Y',strtotime($date)); ? Check out: http://www.php.net/manual/en/function.date.php http://www.php.net/manual/en/function.strtotime.php for more info and date() formats. Note: I haven't done a heap of testing with strtodate() to ensure it's going to return what you expect, but I randomly tested 10 dates in your format between 1977 and 2002 without any problems. Justin French Creative Director http://Indent.com.au on 09/04/02 9:53 PM, nyon ([EMAIL PROTECTED]) wrote: Hi, I need to recall a date data in a MySQL database. The column is set as date timestamp(8). A sample of date is 20020409 I use the PHP Date function to format it back to say 9th April 2002. $date_formated = date($date, 'S M Y' ); However, it's still doesn't appear as formatted. Anyone mind sharing their code to do this? Nyon -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php