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? Link to comment https://forums.phpfreaks.com/topic/147814-solved-check-start-of-week-problem/ 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. Link to comment https://forums.phpfreaks.com/topic/147814-solved-check-start-of-week-problem/#findComment-775882 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. Link to comment https://forums.phpfreaks.com/topic/147814-solved-check-start-of-week-problem/#findComment-775896 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. Link to comment https://forums.phpfreaks.com/topic/147814-solved-check-start-of-week-problem/#findComment-775928 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.