Brian W Posted July 31, 2009 Share Posted July 31, 2009 I need to get the date of last Friday, unless today is Friday in which case get today's date, as a column value. Can't seem to get a grasp on the STR_TO_DATE function or I'm barking up the tree entirely. SELECT STR_TO_DATE('Friday','%W %M %Y') as `Date` FROM Any help is appreciated. Thanks I wish I could use php to make this date, to bad in this situation I have to some how pass the date already correct. Quote Link to comment https://forums.phpfreaks.com/topic/168336-solved-getting-the-right-date/ Share on other sites More sharing options...
roopurt18 Posted July 31, 2009 Share Posted July 31, 2009 IF( DAYOFWEEK( NOW() )=5, NOW(), NOW() - INTERVAL 7 DAY ) AS `MyValue` * Not tested... Quote Link to comment https://forums.phpfreaks.com/topic/168336-solved-getting-the-right-date/#findComment-887966 Share on other sites More sharing options...
Brian W Posted July 31, 2009 Author Share Posted July 31, 2009 hmm, interesting idea. I like it, but it doesn't work. the - 7 gets whatever today is - 7 days (same day of the week). I can use some conditional statements if I can figure out how do do something like ..., NOW() + INTERVAL (7 - DAYOFWEEK( NOW() ) DAY if the day was monday (2), it would work like 7(days in week) - 2 (monday) = 5 2(today) - 5 = - 3 NOW() + -3 = 3 days ago which from Monday is Friday I think Quote Link to comment https://forums.phpfreaks.com/topic/168336-solved-getting-the-right-date/#findComment-887995 Share on other sites More sharing options...
roopurt18 Posted July 31, 2009 Share Posted July 31, 2009 Right, right. My mistake. IF( DAYOFWEEK( NOW() )=6, NOW(), CASE DAYOFWEEK( NOW() ) WHEN 1 THEN NOW() - INTERVAL 2 DAY WHEN 2 THEN NOW() - INTERVAL 3 DAY WHEN 3 THEN NOW() - INTERVAL 4 DAY WHEN 4 THEN NOW() - INTERVAL 5 DAY WHEN 5 THEN NOW() - INTERVAL 6 DAY WHEN 7 THEN NOW() - INTERVAL 1 DAY END ) AS `MyValue Maybe? I dunno! I stopped using MySQL years ago. Quote Link to comment https://forums.phpfreaks.com/topic/168336-solved-getting-the-right-date/#findComment-888013 Share on other sites More sharing options...
Brian W Posted July 31, 2009 Author Share Posted July 31, 2009 Lucky me I don't have to use mysql to get this day anymore! Thanks guys anyways. I managed to get the other developer to write it in Report Writer. Quote Link to comment https://forums.phpfreaks.com/topic/168336-solved-getting-the-right-date/#findComment-888014 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.