Re: [PHP] Simple date question
Hello, This is a reply to an e-mail that you wrote on Wed, 30 Jul 2003 at 19:18, lines prefixed by '' were originally written by you. If I have: $firstdate = 2003-06-28; then how can I get $firstdate plus 4 days? Thanks! date(Y-d-m,mktime(0,0,0,substr($firstdate,5,2),substr($firstdate,8,2),substr($firstdate,0,4)) + (60*60*24*4)); Should do the trick, you can probably use strtotime instead of all the substr()'s but at a guess I would expect the above to be quicker (not that I have benchmarked it). HTH David. -- phpmachine :: The quick and easy to use service providing you with professionally developed PHP scripts :: http://www.phpmachine.com/ Professional Web Development by David Nicholson http://www.djnicholson.com/ QuizSender.com - How well do your friends actually know you? http://www.quizsender.com/ (developed entirely in PHP) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Simple date question
David Nicholson [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Hello, This is a reply to an e-mail that you wrote on Wed, 30 Jul 2003 at 19:18, lines prefixed by '' were originally written by you. If I have: $firstdate = 2003-06-28; then how can I get $firstdate plus 4 days? Thanks! date(Y-d-m,mktime(0,0,0,substr($firstdate,5,2),substr($firstdate,8,2),subs tr($firstdate,0,4)) + (60*60*24*4)); Should do the trick, you can probably use strtotime instead of all the substr()'s but at a guess I would expect the above to be quicker (not that I have benchmarked it). HTH David. -- David's reply was spot on but I thought I'd break it down for you in case you didn't understand... $firstdate = 2003-06-28; // Parse the date list($year, $month, $day) = explode(-, $firstdate); // Get the timestamp for this date.. $ts = mktime(0,0,0,$month,$day,$year); // Add four days to timestamp.. $ts += 345600; // Get year, month, day for new date.. $newdate = date(Y-m-d, $ts); The only thing that I'm doing differntly is the way in which I'm parsing the date. I'm using the list()=explode() method as opposed to substr() becuase this method is not prone to fail when values are not zero filled. Good luck, Kevin -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Simple date question
On Jul 30, 2003, Roy W claimed that: |If I have: | |$firstdate = 2003-06-28; | |then how can I get $firstdate plus 4 days? | |Thanks! It looks like that date may have come from a [mysql] database. If that's the case, you should be able to add 4 days in your query, by using DATE_ADD() check http://www.mysql.com/doc/en/Date_and_time_functions.html Jeff -- Registered Linux user #304026. lynx -source http://jharris.rallycentral.us/jharris.asc | gpg --import Key fingerprint = 52FC 20BD 025A 8C13 5FC6 68C6 9CF9 46C2 B089 0FED Responses to this message should conform to RFC 1855. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] simple date question
Why not just get the month with another call to date(m) as well? Then call date(W) to get the week, if that's required? - Original Message - From: adrian [EMAIL PROTECTED] [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Monday, January 20, 2003 8:42 AM Subject: [PHP] simple date question this is pretty simple but my brain's not working I get the numerical value of a week in the year thus e.g $today = date(W); gives 4 .so this is the 4th week of the year. I want to get the month based on this number. e.g 4 should be january. 7 will be feb etc.. i'm not bothered about being too exact ,where some weeks are in 2 separate months, the earlier month should be displayed.and this is just for 2003. thanks, adrian -- 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] simple date question
why not just call date('m') to get the month? justin -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php