Hi all expertz, I am newly hire intern in web development field and my senior ask me to build mysql query to draw out call history from database. They want me to build query to get call record of: 1- Today 2- Yesterday 3- Last Week 4- this week Just give me sample code or give me hint. we are working on mobile billing app. Please help me it is very necessary for me because i am a fresh intern. Thanks
I would use 4 individual queries to pull the records based on the dates. It's possibly, but would be very complex and probably much slower to try and pull that data in a single query.
Today: SELECT * from `table` where DATE(`datefield`) = DATE(NOW()) Code (markup): Yesterday: SELECT * from `table` where DATE(`datefield`) = DATE(NOW()) - INTERVAL 1 DAY Code (markup): This week: SELECT * from `table` where WEEK(`datefield`) = WEEK(NOW()) Code (markup): Last week: SELECT * from `table` where WEEK(`datefield`) = WEEK(NOW()) - 1 Code (markup):