deansaddigh Posted January 7, 2010 Share Posted January 7, 2010 //Get Current Year $year = date('Y'); //Get Current Month $monthday = date('md'); $year --; $oneyearago = $year.$monthday; echo $oneyearago; All i want to know is,what is the $year.$monthday; doing? is it concatinating the strings? Quote Link to comment Share on other sites More sharing options...
PHP Monkeh Posted January 7, 2010 Share Posted January 7, 2010 Yup that's exactly what that part of the code is doing + is used for addition, whereas . is used for concatenation. Quote Link to comment Share on other sites More sharing options...
cags Posted January 7, 2010 Share Posted January 7, 2010 It takes todays year and stores it in $year, it takes todays month date and stores it in $monthdat, it deducts one from the $year value (giving 2009) it then concatenates that year (ie last year) and month day together before outputting it. So in short, yes. Faux Edit: D'oh. Quote Link to comment Share on other sites More sharing options...
deansaddigh Posted January 7, 2010 Author Share Posted January 7, 2010 Thanks that makes it much simpler. One last question i now need to do the same $year = date(NOW()); //Get Current Month echo $year; $year --; $oneyearago = $year; but now the date field is a time stamp and displays like this 2010-01-05 16:14:40 how can i modify my code to work like with the time stamp intead? Quote Link to comment Share on other sites More sharing options...
deansaddigh Posted January 7, 2010 Author Share Posted January 7, 2010 Please ignore my last question i have figured it out, but it now leads me onto this one. The database holds a time stamp, heres an example of the time stap in one db record. 2008-01-07 11:00:47 Basically i have written code to archive some records based if they are a year old. heres my code but it brings back a record with this time and date stamp 2010-01-05 16:14:40 heres my code and sql statement /***************************************/ /*Archive records one year old/ /***************************************/ //Get Current Year $year = date('Ymd'); //Get Current Month echo $year; $year --; $oneyearago = $year; Sql code $allQuery = dbExec("SELECT * FROM enquiries WHERE date_requested < '".$oneyearago."' $searchSQL $filterSQL "); Quote Link to comment Share on other sites More sharing options...
cags Posted January 7, 2010 Share Posted January 7, 2010 So are you trying to simply get the date from a year before the date you fetch? Simply use the original code you had, but add strtotime($date) as a second parameter wherever you use the date function (where $date is the DateTime from the database). Like so.. $year = date('Y', strtotime($date)); Quote Link to comment Share on other sites More sharing options...
deansaddigh Posted January 7, 2010 Author Share Posted January 7, 2010 Thanks for your help, whats the $date varaible? Quote Link to comment Share on other sites More sharing options...
cags Posted January 7, 2010 Share Posted January 7, 2010 Simply use the original code you had, but add strtotime($date) as a second parameter wherever you use the date function (where $date is the DateTime from the database). Like so.. $year = date('Y', strtotime($date)); Quote Link to comment Share on other sites More sharing options...
deansaddigh Posted January 7, 2010 Author Share Posted January 7, 2010 Im really sorry i still dont understand stupid i know, but what is the $date variable Quote Link to comment Share on other sites More sharing options...
RaythMistwalker Posted January 7, 2010 Share Posted January 7, 2010 date is the value saved in your MySQL database so you have to query to get it. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.