Re: [PHP] echo date('Y-m-d', $mydata->timestamp);
On Sun, April 22, 2007 1:05 am, John Taylor-Johnston wrote: > $mydata->timestamp = "20070419162123"; > > echo date('Y-m-d', $mydata->timestamp); > > > result: 2038-01-18 > > ?? What is wrong?? Should be 2007-04-19? date() takes a Unix timestamp as its input. Unix timestamps are measured as number of seconds from Jan 1, 1970, midnight, GMT, the birth of Disco. [that last was a joke...] You are handing it a pre-formatted date-stamp in MMDDHHIISS format... You could do something like: $t = '20070419162123'; $year = substr($t, 0, 4); $month = substr($t, 4, 2); $day = substr($t, 6, 2); $hour = substr($t, 8, 2); $minutes = substr($t, 10, 2); $seconds = substr($t, 12, 2); echo date(mktime($month, $day, $year, $hour, $minutes, $seconds)); I suspect strtotime() *might* handle your input and give you a Unix timestamp... I also suspect whatever you needed a Unix timestamp for in the first place could have been achieved easier before you got painted into this corner... -- Some people have a "gift" link here. Know what I want? I want you to buy a CD from some indie artist. http://cdbaby.com/browse/from/lynch Yeah, I get a buck. So? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] echo date('Y-m-d', $mydata->timestamp);
It is actually a generated timestamp in MySQL. timestamp(14) Now what? I was hoping to avoid: |echo substr(|$mydata->timestamp|, 0, 8); John |Richard Lynch wrote: On Sun, April 22, 2007 1:05 am, John Taylor-Johnston wrote: $mydata->timestamp = "20070419162123"; echo date('Y-m-d', $mydata->timestamp); result: 2038-01-18 ?? What is wrong?? Should be 2007-04-19? date() takes a Unix timestamp as its input. Unix timestamps are measured as number of seconds from Jan 1, 1970, midnight, GMT, the birth of Disco. [that last was a joke...] You are handing it a pre-formatted date-stamp in MMDDHHIISS format... You could do something like: $t = '20070419162123'; $year = substr($t, 0, 4); $month = substr($t, 4, 2); $day = substr($t, 6, 2); $hour = substr($t, 8, 2); $minutes = substr($t, 10, 2); $seconds = substr($t, 12, 2); echo date(mktime($month, $day, $year, $hour, $minutes, $seconds)); I suspect strtotime() *might* handle your input and give you a Unix timestamp... I also suspect whatever you needed a Unix timestamp for in the first place could have been achieved easier before you got painted into this corner...
Re: [PHP] echo date('Y-m-d', $mydata->timestamp);
On Sunday 22 April 2007 08:33, John Taylor-Johnston wrote: > It is actually a generated timestamp in MySQL. > timestamp(14) Well, then just use the query to decide how it should look like. Mysql timestamp is amazingly easy to work with. whatevertable,date_format(timestamp_table, 'what should it look like') as timestamp or use another name if you need both like I do. > > Now what? I was hoping to avoid: > |echo substr(|$mydata->timestamp|, 0, 8); > > John > > |Richard Lynch wrote: > | > > On Sun, April 22, 2007 1:05 am, John Taylor-Johnston wrote: > >> $mydata->timestamp = "20070419162123"; > >> > >> echo date('Y-m-d', $mydata->timestamp); > >> > >> > >> result: 2038-01-18 > >> > >> ?? What is wrong?? Should be 2007-04-19? > > > > date() takes a Unix timestamp as its input. > > > > Unix timestamps are measured as number of seconds from Jan 1, 1970, > > midnight, GMT, the birth of Disco. > > [that last was a joke...] > > > > You are handing it a pre-formatted date-stamp in MMDDHHIISS format... > > > > You could do something like: > > $t = '20070419162123'; > > $year = substr($t, 0, 4); > > $month = substr($t, 4, 2); > > $day = substr($t, 6, 2); > > $hour = substr($t, 8, 2); > > $minutes = substr($t, 10, 2); > > $seconds = substr($t, 12, 2); > > echo date(mktime($month, $day, $year, $hour, $minutes, $seconds)); > > > > I suspect strtotime() *might* handle your input and give you a Unix > > timestamp... > > > > I also suspect whatever you needed a Unix timestamp for in the first > > place could have been achieved easier before you got painted into this > > corner... -- --- Børge http://www.arivene.net --- -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] echo date('Y-m-d', $mydata->timestamp);
John Taylor-Johnston wrote: > > It is actually a generated timestamp in MySQL. > timestamp(14) > Now what? I was hoping to avoid: > |echo substr(|$mydata->timestamp|, 0, 8); the simplest answer is actually yto make mySQL give you the data in unix timestamp format in the first place: SELECT UNIX_TIMESTAMP(my_field) AS my_timestamp FROM foo WHERE id=1; > > John > > |Richard Lynch wrote: >> On Sun, April 22, 2007 1:05 am, John Taylor-Johnston wrote: >> >>> $mydata->timestamp = "20070419162123"; >>> >>> echo date('Y-m-d', $mydata->timestamp); >>> >>> >>> result: 2038-01-18 >>> >>> ?? What is wrong?? Should be 2007-04-19? >>> >> >> date() takes a Unix timestamp as its input. >> >> Unix timestamps are measured as number of seconds from Jan 1, 1970, >> midnight, GMT, the birth of Disco. >> [that last was a joke...] >> >> You are handing it a pre-formatted date-stamp in MMDDHHIISS format... >> >> You could do something like: >> $t = '20070419162123'; >> $year = substr($t, 0, 4); >> $month = substr($t, 4, 2); >> $day = substr($t, 6, 2); >> $hour = substr($t, 8, 2); >> $minutes = substr($t, 10, 2); >> $seconds = substr($t, 12, 2); >> echo date(mktime($month, $day, $year, $hour, $minutes, $seconds)); >> >> I suspect strtotime() *might* handle your input and give you a Unix >> timestamp... >> >> I also suspect whatever you needed a Unix timestamp for in the first >> place could have been achieved easier before you got painted into this >> corner... >> >> > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] echo date('Y-m-d', $mydata->timestamp);
You are misunderstanding what timestamp means. The value of a timestamp is from UNIX epoch http://en.wikipedia.org/wiki/Unix_time. It is calculated by the number of seconds after January 1st, 1970. Also note, that you are overflowing the integer, which is giving you a http://en.wikipedia.org/wiki/Year_2038_problem Y2K38 problem. If you want the UNIX timestamp of 4/19/2007 16:21:23, you can do mktime(16,21,23,4,19,2007); (http://us.php.net/manual/en/function.mktime.php). -Logan -Original Message- From: John Taylor-Johnston [mailto:[EMAIL PROTECTED] Sent: Sunday, April 22, 2007 2:05 AM To: PHP-General Cc: John Taylor-Johnston Subject: [PHP] echo date('Y-m-d', $mydata->timestamp); $mydata->timestamp = "20070419162123"; echo date('Y-m-d', $mydata->timestamp); result: 2038-01-18 ?? What is wrong?? Should be 2007-04-19? -- 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] echo date('Y-m-d', $mydata->timestamp);
Use the MySQL function that converts timestamp into Unixtime. Or, better yet, use the MySQL function that outputs exactly the date format you want, without dinking around with Unix timestamp in the middle. http://dev.mysql.com/ Search for date_format() I do believe. It's gonna be a whole lot like PHP 'date' function, only with % signs, as I recall. On Sun, April 22, 2007 1:33 am, John Taylor-Johnston wrote: > > It is actually a generated timestamp in MySQL. > timestamp(14) > Now what? I was hoping to avoid: > |echo substr(|$mydata->timestamp|, 0, 8); > > John > > |Richard Lynch wrote: >> On Sun, April 22, 2007 1:05 am, John Taylor-Johnston wrote: >> >>> $mydata->timestamp = "20070419162123"; >>> >>> echo date('Y-m-d', $mydata->timestamp); >>> >>> >>> result: 2038-01-18 >>> >>> ?? What is wrong?? Should be 2007-04-19? >>> >> >> date() takes a Unix timestamp as its input. >> >> Unix timestamps are measured as number of seconds from Jan 1, 1970, >> midnight, GMT, the birth of Disco. >> [that last was a joke...] >> >> You are handing it a pre-formatted date-stamp in MMDDHHIISS >> format... >> >> You could do something like: >> $t = '20070419162123'; >> $year = substr($t, 0, 4); >> $month = substr($t, 4, 2); >> $day = substr($t, 6, 2); >> $hour = substr($t, 8, 2); >> $minutes = substr($t, 10, 2); >> $seconds = substr($t, 12, 2); >> echo date(mktime($month, $day, $year, $hour, $minutes, $seconds)); >> >> I suspect strtotime() *might* handle your input and give you a Unix >> timestamp... >> >> I also suspect whatever you needed a Unix timestamp for in the first >> place could have been achieved easier before you got painted into >> this >> corner... >> >> > -- Some people have a "gift" link here. Know what I want? I want you to buy a CD from some indie artist. http://cdbaby.com/browse/from/lynch Yeah, I get a buck. So? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php