473,699 Members | 2,907 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Date range sorting

Hi,

I am wondering how to return data by date ranges, where I return all
data made:

Today,
(Every individual day of the week up to 1 week ago - eg. Everything for
last Monday, last Tuesday etc)
Two/Three weeks ago
Anything over three weeks ago

Also, is this something best done in PHP after a full query or during
SQL?

Aug 15 '05 #1
2 1491
jg*****@gmail.c om wrote:
Hi,

I am wondering how to return data by date ranges, where I return all
data made:

Today,
(Every individual day of the week up to 1 week ago - eg. Everything for
last Monday, last Tuesday etc)
Two/Three weeks ago
Anything over three weeks ago


create table a ( d date);

insert into a values
('2005-08-15'), ('2005-08-12'), ('2005-08-11'),
('2005-08-05'), ('2005-07-29'), ('2005-06-15');

select *, case
when to_days(curdate ()) - to_days(d) < 7
then to_days(curdate ()) - to_days(d)
when to_days(curdate ()) - to_days(d) between 7 and 21
then 14
else 21 end as dayCategory
from a
order by dayCategory;

If you need an aggregate, such as the count of such records per category:

select count(*), ... as dayCategory
from a
group by dayCategory;

Regards,
Bill K.
Aug 15 '05 #2
Wow! That was really helpful! Many thanks!!

Aug 15 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
5215
by: androtech | last post by:
Hello, I'm looking for a function that returns a date range for a specified week number of the year. I'm not able to find functions like this anywhere. Any pointers/help would be much appreciated. TIA
10
32479
by: Mat | last post by:
Hi, I have a table with two column, date and data I would like to do a set of queries to generate statistics on the data, such as count(data) for month blocks and year blocks. What is the best way to accomplish this? dd/mm/yy date | data ---------------
9
7280
by: PamelaDV | last post by:
I have two problems, actually. I am looking to see if there is a function that will return the day of the week (Monday, Tuesday, Wednesday, etc...) from a date. For instance 2/27/04 is a Friday. Also is there a way to group dates by week? I have a user who wants a report to group by week. I know I could create a table and assign dates to a week, but I'm wondering if anyone has anything out there already done that may be a little bit...
1
2448
by: alpha_male | last post by:
Can anybody help to create code which would create new table from linked table and additionally will add date stamp for the name of new table? For example tblHello is linked table and the code would create a table tblHello311204 at the 31st december of 2004. Be well, Ivars
18
38237
by: dfetrow410 | last post by:
Anyone have some code that will do this? Dave
7
3061
by: Middletree | last post by:
I am trying to display dates in a spreadsheet, but the dates need to be in a format that will allow them to be sorted in Excel. The datatype in the SQL Server database is datetime. In this case, I need to display the date only, not the time. But I don't want to change the datatype in the database because the time is used in other places. So what I am doing is pulling it out of the database, then modifying it in ASP/VBScript by using the...
20
7893
by: Ajay Bathija | last post by:
Hi: I am new to this forum. If I am not through in my explanation then please let me know. I need help in figuring out how I can accomplish the following. I am using VB.net for the front end application, and connecting it to the Access database In the VB form I have a data grid. I am trying to fill the datasource of the data grid from the access table.
6
1559
by: vdicarlo | last post by:
I am a programming amateur and a Python newbie who needs to convert about 100,000,000 strings of the form "1999-12-30" into ordinal dates for sorting, comparison, and calculations. Though my script does a ton of heavy calculational lifting (for which numpy and psyco are a blessing) besides converting dates, it still seems to like to linger in the datetime and time libraries. (Maybe there's a hot module in there with a cute little function...
4
2849
Sandboxer
by: Sandboxer | last post by:
I want to be able to program Access to provide for me, by individual day, what my contract obligations are to my customers. Will Access recognize all the individual days in between a date range (simply a "from" date and a "to" date)? Additionally, I need to delivery a specific quantity of product when the customer's inventory is within about parameter levels. EXAMPLE: "During the Date Range January 1, 2010 through April 30, 2010 when...
3
1285
by: ApeX | last post by:
hello, can anybody please give me some advice or a pseudocode for the following: i got two datatables filled with dates, i need to fill a third datatable with values from the other two but the trick is: first datatable ****************** 28.8.2007 - 2.10.2007 5.10.2007 - 4.11.2007
0
8704
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8623
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9187
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9054
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8936
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8894
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5879
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4390
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
3
2015
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.