fry2010 Posted March 3, 2009 Share Posted March 3, 2009 Can someone help me to solve this problem I cant quite get my head round? I need to store figures on a daily basis. They can be positive and negative numbers. I will store these in a database. I need to find the accumulative total for the current week. So say today is wednesday, I need to total mon and tuesday. But then if the day is friday I will need to calculate mon, tue, wed and thursday... So basically I need to find the start of the week then I can do my calculations from that. I am using the mysql setting for dates in the database so YYYY-MM-DD. I will also need to find out the total for last week, but if today is tuesday then I cant just count back 8 days to find the start it will need to be dynamic. I suppose once I find the start of the current week this might not be an issue. Also I need to find the start of the current month and last month. Anyone know what I should be using for this? Quote Link to comment Share on other sites More sharing options...
fry2010 Posted March 3, 2009 Author Share Posted March 3, 2009 Anyone have any ideas? Im totally lost as to how I could do this. Quote Link to comment Share on other sites More sharing options...
samshel Posted March 3, 2009 Share Posted March 3, 2009 <?php $dt = "2010-03-11"; $dayToday = date("N", strtotime($dt)); $dayDiff = $dayToday - 1;// 1 is for monday.. $dayStartOfWeek = date("Y-m-d", strtotime($dt) - $dayDiff * 86400); echo $dayStartOfWeek; ?> this will give u start day of the week (date on monday of that week), provided any date...hope this is what u r looking for. Quote Link to comment Share on other sites More sharing options...
fry2010 Posted March 4, 2009 Author Share Posted March 4, 2009 awesome, works a treat. Thank you very much samshel. Iv actually just had a look through the code and tweaked a few things to see how it returns the value etc.. I have to say it is amazing that you could just cook something like that up so quick. This kind of thing totally eludes me. Amazing stuff. 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.