Re: [PHP] converting seconds since unix epoc to date array
beware of dates before 1969. That problem mostly occurs on windows systems, and in fact it's dates before 1 jan 1970 0:00 - php on windows will issue a warning if you try to use dates like that Can anyone tell me how to convert a date stored in the format -MM-DD to an integer of seconds since unix epoc, As for converting a -MM-DD date to epoch seconds, if it comes for mysql (as suggested) you should use select UNIX_TIMESTAMP(date_column), * FROM tablename; From another source, strtotime should work on this format. Consider the 1 jan 1970 problem, check your error logs, call error_reporting(E_ALL); to see for any additional problems... the problem might as well be a typo in your varname. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] converting seconds since unix epoc to date array
Can anyone tell me how to convert a date stored in the format -MM-DD to an integer of seconds since unix epoc, then add $daysToAdd days to this value (I suppose if the integer was a number of seconds it would have to be $daysToAdd*60*60*24 to get the number of seconds to add) then convert the new value to a timestamp which I can output using the function string date ( string format [, int timestamp]) I tried doing this with mktime() and couple different ways using strtotime() and also with strftime() but I kept getting -1 as the result for strtotime() indicating the function couldn't interpret the given date. I've been through all the date-related functions in the manual I can think of, but I'm stumpped on this one...
Re: [PHP] converting seconds since unix epoc to date array
Hi, Try $date=-MM_DD; $da=explode(-,$date); Now $Y=$da['0']; $M=$da['1']; $D=$da['2']; then use mktime(); Hope you will get the results. zareef ahmed --- Jason FB [EMAIL PROTECTED] wrote: Can anyone tell me how to convert a date stored in the format -MM-DD to an integer of seconds since unix epoc, then add $daysToAdd days to this value (I suppose if the integer was a number of seconds it would have to be $daysToAdd*60*60*24 to get the number of seconds to add) then convert the new value to a timestamp which I can output using the function string date ( string format [, int timestamp]) I tried doing this with mktime() and couple different ways using strtotime() and also with strftime() but I kept getting -1 as the result for strtotime() indicating the function couldn't interpret the given date. I've been through all the date-related functions in the manual I can think of, but I'm stumpped on this one... = Homepage :: http://www.zasaifi.com __ Do you Yahoo!? Take Yahoo! Mail with you! Get it on your mobile phone. http://mobile.yahoo.com/maildemo -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] converting seconds since unix epoc to date array
Jason FB wrote: Can anyone tell me how to convert a date stored in the format -MM-DD to an integer of seconds since unix epoc, then add $daysToAdd days to this value (I suppose if the integer was a number of seconds it would have to be $daysToAdd*60*60*24 to get the number of seconds to add) then convert the new value to a timestamp which I can output using the function string date ( string format [, int timestamp]) Is this a MySQL timestamp? If so, you can use TO_UNIXTIME() in your query to return a Unix timestamp instead of a MySQL one. You can use DATE_ADD() to add days to the timestamp. You can also use DATE_FORMAT() to format the timestamp before it's returned also. If you don't want to do that, what's wrong with strtotime('-MM-DD') to get the unix timestamp? -- ---John Holmes... Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/ php|architect: The Magazine for PHP Professionals www.phparch.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] converting seconds since unix epoc to date array
Jason, This seems to work fine for me: ? $daysToAdd = 5; $secondsToAdd = $daysToAdd * 86400; $dateIn = 2004-07-24; $dateInStamp= strtotime($dateIn); echo date('m/d/Y h:i:s',$dateInStamp+$secondsToAdd); ? ... as does the more condensed version: ? echo date('m/d/Y h:i:s',strtotime(2004-07-24)+(5*86400)); ? If strtotime() is returning -1, that means that it's having trouble converting your -MM-DD date to a timestamp. The common pitfall is that you've got the month and day mixed up (-DD-MM), or that you're not using 2 digit numbers on the day and month (and 4 digit on the year). If you're having trouble with strtotime(), ech out the date you're trying to convert, to make sure it's what you're expecting. It's also worth pointing out that we've made no considerations for timezones, daylight savings, etc. UNIX timestamps are all GMT, so if the times you're seeing are not as expected (and the dates you're collecting aren't GMT dates, then you'll need to dig a lot deeper -- it's depends how much accuracy you want. Justin French On 07/09/2004, at 1:59 PM, Jason FB wrote: Can anyone tell me how to convert a date stored in the format -MM-DD to an integer of seconds since unix epoc, then add $daysToAdd days to this value (I suppose if the integer was a number of seconds it would have to be $daysToAdd*60*60*24 to get the number of seconds to add) then convert the new value to a timestamp which I can output using the function string date ( string format [, int timestamp]) I tried doing this with mktime() and couple different ways using strtotime() and also with strftime() but I kept getting -1 as the result for strtotime() indicating the function couldn't interpret the given date. I've been through all the date-related functions in the manual I can think of, but I'm stumpped on this one... --- Justin French http://indent.com.au -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] converting seconds since unix epoc to date array
How is the date stored, MySQL db??? if so, you can select dates out as unix timestamps. Otherwise i would use mktime or strtotime... Jason Jason FB [EMAIL PROTECTED] wrote: Can anyone tell me how to convert a date stored in the format -MM-DD to an integer of seconds since unix epoc, then add $daysToAdd days to this value (I suppose if the integer was a number of seconds it would have to be $daysToAdd*60*60*24 to get the number of seconds to add) then convert the new value to a timestamp which I can output using the function string date ( string format [, int timestamp]) I tried doing this with mktime() and couple different ways using strtotime() and also with strftime() but I kept getting -1 as the result for strtotime() indicating the function couldn't interpret the given date. I've been through all the date-related functions in the manual I can think of, but I'm stumpped on this one... -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] converting seconds since unix epoc to date array
beware of dates before 1969. Justin French [EMAIL PROTECTED] wrote: Jason, This seems to work fine for me: ? $daysToAdd= 5; $secondsToAdd = $daysToAdd * 86400; $dateIn = 2004-07-24; $dateInStamp = strtotime($dateIn); echo date('m/d/Y h:i:s',$dateInStamp+$secondsToAdd); ? ... as does the more condensed version: ? echo date('m/d/Y h:i:s',strtotime(2004-07-24)+(5*86400)); ? If strtotime() is returning -1, that means that it's having trouble converting your -MM-DD date to a timestamp. The common pitfall is that you've got the month and day mixed up (-DD-MM), or that you're not using 2 digit numbers on the day and month (and 4 digit on the year). If you're having trouble with strtotime(), ech out the date you're trying to convert, to make sure it's what you're expecting. It's also worth pointing out that we've made no considerations for timezones, daylight savings, etc. UNIX timestamps are all GMT, so if the times you're seeing are not as expected (and the dates you're collecting aren't GMT dates, then you'll need to dig a lot deeper -- it's depends how much accuracy you want. Justin French On 07/09/2004, at 1:59 PM, Jason FB wrote: Can anyone tell me how to convert a date stored in the format -MM-DD to an integer of seconds since unix epoc, then add $daysToAdd days to this value (I suppose if the integer was a number of seconds it would have to be $daysToAdd*60*60*24 to get the number of seconds to add) then convert the new value to a timestamp which I can output using the function string date ( string format [, int timestamp]) I tried doing this with mktime() and couple different ways using strtotime() and also with strftime() but I kept getting -1 as the result for strtotime() indicating the function couldn't interpret the given date. I've been through all the date-related functions in the manual I can think of, but I'm stumpped on this one... --- Justin French http://indent.com.au -- 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