[PHP] datetime formatting problem
hi all - this is probably straight forward, but i'm learning and would appreciate any insight. i'm using the datetime type in mysql and have been able to successsfully pull the data records's date, but it's failing out and giving me the current time [as in what it says on my system's clock] basically i'm just spitting out all the rows to an html table and would like to have the date AND time formatted as is in the date(...) function at the top of the code demo. thanks! matt / begin code demo function formatDate($val) { $arr = explode(-, $val); return date(M d, Y g:i A, mktime(0,0,0, $arr[1], $arr[2], $arr[0])); } // open database connection $connection = mysql_connect($host, $user, $pass) or die (Unable to connect!); // select database mysql_select_db($db) or die (Unable to select database!); // generate and execute query $query = SELECT * FROM outdoor ORDER BY id ASC; $result = mysql_query($query) or die (Error in query: $query. . mysql_error()); // if records present if (mysql_num_rows($result) 0) { // iterate through resultset // print title with links to edit and delete scripts while($row = mysql_fetch_object($result)) { ? tr td? echo $row-id; ?/td td? echo $row-name; ?/td tda href=mailto:? echo $row-email; ?? echo $row-email; ?/a/td td? echo $row-zip ?/td td? echo formatDate($row-date); ?/td td? echo $row-club_member ?/td td? echo $row-driver ?/td !-- tdfont size=-1? echo $row-active ?/font/td -- tdcentera href=edit.php?id=? echo $row-id; ?img src=notepad.gif alt= width=16 height=16 border=0/a nbsp; a href=delete.php?id=? echo $row-id; ?img src=trashcan.gif alt= width=16 height=16 border=0/a/center/td /tr ? } } -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] datetime formatting problem
Isn't date a reserved word? hi all - this is probably straight forward, but i'm learning and would appreciate any insight. i'm using the datetime type in mysql and have been able to successsfully pull the data records's date, but it's failing out and giving me the current time [as in what it says on my system's clock] basically i'm just spitting out all the rows to an html table and would like to have the date AND time formatted as is in the date(...) function at the top of the code demo. thanks! matt / begin code demo function formatDate($val) { $arr = explode(-, $val); return date(M d, Y g:i A, mktime(0,0,0, $arr[1], $arr[2], $arr[0])); } // open database connection $connection = mysql_connect($host, $user, $pass) or die (Unable to connect!); // select database mysql_select_db($db) or die (Unable to select database!); // generate and execute query $query = SELECT * FROM outdoor ORDER BY id ASC; $result = mysql_query($query) or die (Error in query: $query. . mysql_error()); // if records present if (mysql_num_rows($result) 0) { // iterate through resultset // print title with links to edit and delete scripts while($row = mysql_fetch_object($result)) { ? tr td? echo $row-id; ?/td td? echo $row-name; ?/td tda href=mailto:? echo $row-email; ?? echo $row-email; ?/a/td td? echo $row-zip ?/td td? echo formatDate($row-date); ?/td td? echo $row-club_member ?/td td? echo $row-driver ?/td !-- tdfont size=-1? echo $row-active ?/font/td -- tdcentera href=edit.php?id=? echo $row-id; ?img src=notepad.gif alt= width=16 height=16 border=0/a a href=delete.php?id=? echo $row-id; ?img src=trashcan.gif alt= width=16 height=16 border=0/a/center/td /tr ? } } -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] datetime formatting problem
Daniel Clark [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Isn't date a reserved word? date and dateTime are not reserved in MySQL and can be used as column names. hi all - this is probably straight forward, but i'm learning and would appreciate any insight. i'm using the datetime type in mysql and have been able to successsfully pull the data records's date, but it's failing out and giving me the current time [as in what it says on my system's clock] basically i'm just spitting out all the rows to an html table and would like to have the date AND time formatted as is in the date(...) function at the top of the code demo. thanks! matt / begin code demo function formatDate($val) { $arr = explode(-, $val); return date(M d, Y g:i A, mktime(0,0,0, $arr[1], $arr[2], $arr[0])); } Hi Matt, try this: function formatDate($val) { $timestamp = strtotime($val); return date('M d, Y g:i A', $timestamp); } Regards, Torsten Roehr // open database connection $connection = mysql_connect($host, $user, $pass) or die (Unable to connect!); // select database mysql_select_db($db) or die (Unable to select database!); // generate and execute query $query = SELECT * FROM outdoor ORDER BY id ASC; $result = mysql_query($query) or die (Error in query: $query. . mysql_error()); // if records present if (mysql_num_rows($result) 0) { // iterate through resultset // print title with links to edit and delete scripts while($row = mysql_fetch_object($result)) { ? tr td? echo $row-id; ?/td td? echo $row-name; ?/td tda href=mailto:? echo $row-email; ?? echo $row-email; ?/a/td td? echo $row-zip ?/td td? echo formatDate($row-date); ?/td td? echo $row-club_member ?/td td? echo $row-driver ?/td !-- tdfont size=-1? echo $row-active ?/font/td -- tdcentera href=edit.php?id=? echo $row-id; ?img src=notepad.gif alt= width=16 height=16 border=0/a a href=delete.php?id=? echo $row-id; ?img src=trashcan.gif alt= width=16 height=16 border=0/a/center/td /tr ? } } -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] datetime formatting problem
[snip /] Hi Matt, try this: function formatDate($val) { $timestamp = strtotime($val); return date('M d, Y g:i A', $timestamp); } strtotime possibly will not work if your date is 01/01/1970. [snip /] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] datetime formatting problem
thanks a bunch torsten. it worked like a charm and i'm off to read up some more on strtotime. best, m. -Original Message- From: Torsten Roehr [mailto:[EMAIL PROTECTED] Sent: Friday, May 28, 2004 2:07 PM To: [EMAIL PROTECTED] Subject: Re: [PHP] datetime formatting problem Daniel Clark [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Isn't date a reserved word? date and dateTime are not reserved in MySQL and can be used as column names. hi all - this is probably straight forward, but i'm learning and would appreciate any insight. i'm using the datetime type in mysql and have been able to successsfully pull the data records's date, but it's failing out and giving me the current time [as in what it says on my system's clock] basically i'm just spitting out all the rows to an html table and would like to have the date AND time formatted as is in the date(...) function at the top of the code demo. thanks! matt / begin code demo function formatDate($val) { $arr = explode(-, $val); return date(M d, Y g:i A, mktime(0,0,0, $arr[1], $arr[2], $arr[0])); } Hi Matt, try this: function formatDate($val) { $timestamp = strtotime($val); return date('M d, Y g:i A', $timestamp); } Regards, Torsten Roehr // open database connection $connection = mysql_connect($host, $user, $pass) or die (Unable to connect!); // select database mysql_select_db($db) or die (Unable to select database!); // generate and execute query $query = SELECT * FROM outdoor ORDER BY id ASC; $result = mysql_query($query) or die (Error in query: $query. . mysql_error()); // if records present if (mysql_num_rows($result) 0) { // iterate through resultset // print title with links to edit and delete scripts while($row = mysql_fetch_object($result)) { ? tr td? echo $row-id; ?/td td? echo $row-name; ?/td tda href=mailto:? echo $row-email; ?? echo $row-email; ?/a/td td? echo $row-zip ?/td td? echo formatDate($row-date); ?/td td? echo $row-club_member ?/td td? echo $row-driver ?/td !-- tdfont size=-1? echo $row-active ?/font/td -- tdcentera href=edit.php?id=? echo $row-id; ?img src=notepad.gif alt= width=16 height=16 border=0/a a href=delete.php?id=? echo $row-id; ?img src=trashcan.gif alt= width=16 height=16 border=0/a/center/td /tr ? } } -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] datetime formatting problem
appreciate the headsup, but all times will be from when record is inserted which will not be possible before today. thanks, m. -Original Message- From: Jordan S. Jones [mailto:[EMAIL PROTECTED] Sent: Friday, May 28, 2004 2:20 PM To: [EMAIL PROTECTED] Subject: Re: [PHP] datetime formatting problem [snip /] Hi Matt, try this: function formatDate($val) { $timestamp = strtotime($val); return date('M d, Y g:i A', $timestamp); } strtotime possibly will not work if your date is 01/01/1970. [snip /] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] datetime formatting problem
Try strftime it allows you to take a timestamp created by time() and format it as required. heres the man page for it: http://www.php.net/manual/en/function.strftime.php Matt Newell [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] thanks a bunch torsten. it worked like a charm and i'm off to read up some more on strtotime. best, m. -Original Message- From: Torsten Roehr [mailto:[EMAIL PROTECTED] Sent: Friday, May 28, 2004 2:07 PM To: [EMAIL PROTECTED] Subject: Re: [PHP] datetime formatting problem Daniel Clark [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Isn't date a reserved word? date and dateTime are not reserved in MySQL and can be used as column names. hi all - this is probably straight forward, but i'm learning and would appreciate any insight. i'm using the datetime type in mysql and have been able to successsfully pull the data records's date, but it's failing out and giving me the current time [as in what it says on my system's clock] basically i'm just spitting out all the rows to an html table and would like to have the date AND time formatted as is in the date(...) function at the top of the code demo. thanks! matt / begin code demo function formatDate($val) { $arr = explode(-, $val); return date(M d, Y g:i A, mktime(0,0,0, $arr[1], $arr[2], $arr[0])); } Hi Matt, try this: function formatDate($val) { $timestamp = strtotime($val); return date('M d, Y g:i A', $timestamp); } Regards, Torsten Roehr // open database connection $connection = mysql_connect($host, $user, $pass) or die (Unable to connect!); // select database mysql_select_db($db) or die (Unable to select database!); // generate and execute query $query = SELECT * FROM outdoor ORDER BY id ASC; $result = mysql_query($query) or die (Error in query: $query. . mysql_error()); // if records present if (mysql_num_rows($result) 0) { // iterate through resultset // print title with links to edit and delete scripts while($row = mysql_fetch_object($result)) { ? tr td? echo $row-id; ?/td td? echo $row-name; ?/td tda href=mailto:? echo $row-email; ?? echo $row-email; ?/a/td td? echo $row-zip ?/td td? echo formatDate($row-date); ?/td td? echo $row-club_member ?/td td? echo $row-driver ?/td !-- tdfont size=-1? echo $row-active ?/font/td -- tdcentera href=edit.php?id=? echo $row-id; ?img src=notepad.gif alt= width=16 height=16 border=0/a a href=delete.php?id=? echo $row-id; ?img src=trashcan.gif alt= width=16 height=16 border=0/a/center/td /tr ? } } -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php