Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 925 Vote(s) - 3.5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
sqlite select with condition on date

#1
I have an sqlite table with Date of Birth. I would like to execute a query to select those records where the age is more than 30.
I have tried the following but it doesn't work:

select * from mytable where dob > '1/Jan/1980'
select * from mytable where dob > '1980-01-01'

Reply

#2
Try writing using the date format 'YYYY-MM-DD'

select * from mytable where dob > '1980-01-01'

A more programic way would be something like this:

select * from mytable where datediff(dob, now()) > 30

You'll Need to find specific syntax for sqlite.
Reply

#3
Using the magic docs at [the sqlite website][1]:

select * from mytable where dob < date('now','-30 years');


[1]:

[To see links please register here]

Reply

#4
Some thing like this could be used:


select dateofbirth from customer Where DateofBirth BETWEEN date('1004-01-01') AND date('1980-12-31');
select dateofbirth from customer where date(dateofbirth)>date('1980-12-01');
select * from customer where date(dateofbirth) < date('now','-30 years');

**If you are using Sqlite V3.7.12 or greater**

Dont use `date(dateofbirth)` just use `dateofbirth`. So your query would look like this:

select * from customer where dateofbirth < date('now','-30 years');
Reply

#5
select * from mytable where date(dob) > date('1980-01-10')
Reply

#6
QLite3 has some cool new date functions. Per the [docs site](

[To see links please register here]

) you can use **date()**, **time()**, **datetime()**, **julianday()**, **unixepoch()**, or **strftime()** depending on how your column data is formatted.

If you use **strftime()**, like my suggestion below, then you have to make sure that your column data is formatted the same way as your strftime string.

You would probably want something like:

```SELECT * FROM mytable WHERE dob < strftime("%m/%d/%Y", 'now', '-30 year');```

Note that you might have to change the format string here to match your own.

---

And here's some code that I use personally to give you a better idea of how powerful it is. It lets me get all the orders from the previous 3 months, not including this month.

```SELECT * FROM orders WHERE SHIPPEDDATE > strftime('%m/%d/%Y', 'now', 'start of month', '-3 month');```

The modifiers are very powerful with sqlite. The first string inside **strftime()** is the format, the 2nd string is when you want the date to start. 'Start of month' puts the day to 1, and '-3 month' goes back 3 months. So if I ran that today (08/03/2022), the date it uses would be 05/01/2022.
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through