Re: [PHP] getting a date 25 years back
Merlin wrote: Hi there, I am trying to create a date which is 25 years back from today. The purpose of this is to be able to query a mysql database date field for columns smaller than this date. I tried this: $years = 25; $start_from = date(Y-m-d,strtotime(- .$years. year)); Somehow it always ads the years instead of subtracting. Has anybody an idea on how to do that? Thank you in advance for any help, Merlin http://us4.php.net/mktime mktime ( date ( G ), date ( i ), date ( s ), date( n ), date ( j ), date ( Y ) - 25 ); -- John C. Nichel ÜberGeek KegWorks.com 716.856.9675 [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] getting a date 25 years back
On Wednesday 15 December 2004 03:21, Merlin wrote: I am trying to create a date which is 25 years back from today. The purpose of this is to be able to query a mysql database date field for columns smaller than this date. I tried this: $years = 25; $start_from = date(Y-m-d,strtotime(- .$years. year)); Somehow it always ads the years instead of subtracting. Try: strtotime($years years ago); -- Jason Wong - Gremlins Associates - www.gremlins.biz Open Source Software Systems Integrators * Web Design Hosting * Internet Intranet Applications Development * -- Search the list archives before you post http://marc.theaimsgroup.com/?l=php-general -- /* printk (%s: This looks like a LART board to me. ,module_name); linux-2.6.6/drivers/mtd/devices/lart.c */ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] getting a date 25 years back
Merlin wrote: Hi there, I am trying to create a date which is 25 years back from today. The purpose of this is to be able to query a mysql database date field for columns smaller than this date. I tried this: $years = 25; $start_from = date(Y-m-d,strtotime(- .$years. year)); Somehow it always ads the years instead of subtracting. Has anybody an idea on how to do that? You can use mktime() and subtract 25 from the year argument. Or just do it in your query... SELECT * FROM yourtable WHERE your_date_column NOW() - INTERVAL 25 YEAR; -- ---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] getting a date 25 years back
Merlin wrote: I am trying to create a date which is 25 years back from today. The purpose of this is to be able to query a mysql database date field for columns smaller than this date. I tried this: $years = 25; // $start_from = date(Y-m-d,strtotime(- .$years. year)); Somehow it always ads the years instead of subtracting. Has anybody an idea on how to do that? You can do this in all MySQL: select ... where date_field = sub_date(now(), interval 25 years) Or you could try: $back_then = mktime(0, 0, 0, date('m'), date('d'), date('Y') - 25); $start_from = date(Y-m-d, $back_then); -- Like Music? http://l-i-e.com/artists.htm -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] getting a date 25 years back
Richard Lynch wrote: Merlin wrote: I am trying to create a date which is 25 years back from today. The purpose of this is to be able to query a mysql database date field for columns smaller than this date. I tried this: $years = 25; // $start_from = date(Y-m-d,strtotime(- .$years. year)); Somehow it always ads the years instead of subtracting. Has anybody an idea on how to do that? You can do this in all MySQL: select ... where date_field = sub_date(now(), interval 25 years) Or you could try: $back_then = mktime(0, 0, 0, date('m'), date('d'), date('Y') - 25); $start_from = date(Y-m-d, $back_then); thank you everybody for your help. I used this which works excellent: $back_then = mktime(0, 0, 0, date('m'), date('d'), date('Y') - 25); Thanx, Merlin -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] getting a date 25 years back
Merlin wrote: Hi there, I am trying to create a date which is 25 years back from today. The purpose of this is to be able to query a mysql database date field for columns smaller than this date. I tried this: $years = 25; $start_from = date(Y-m-d,strtotime(- .$years. year)); Somehow it always ads the years instead of subtracting. Has anybody an idea on how to do that? Thank you in advance for any help, Merlin http://us4.php.net/mktime -- John C. Nichel ÜberGeek KegWorks.com 716.856.9675 [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] getting a date 25 years back
You should do date arithmetic using the Unix date format (number of seconds since 1970). I think these string format dates are not appropriate. Mario Merlin wrote: Hi there, I am trying to create a date which is 25 years back from today. The purpose of this is to be able to query a mysql database date field for columns smaller than this date. I tried this: $years = 25; $start_from = date(Y-m-d,strtotime(- .$years. year)); Somehow it always ads the years instead of subtracting. Has anybody an idea on how to do that? Thank you in advance for any help, Merlin -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php