How to find the difference in terms of days from YYYY_MM_DD formatted dates in bigsql? - bigsql

I want to find the difference between two dates in YYYY-MM-DD format. For example, I have 2 dates 2018-10-31 and 2018-11-07. I want to find the difference in number of days between those two dates (7 days) in BigSql. I have gone through stack overflow and other websites but couldn't find anything that works as there are very few resources for BigSql.
I have tried below query which works fine for sql server but not for bigsql :
SELECT DATEDIFF(DAY, '2018-10-31', '2018-11-07')
Any help would be appreciated
Thanks

Finally after continuous efforts I found something that worked for me posting here if in case someone looking for the the same:
SELECT DAYS_BETWEEN ('2018-10-31', '2018-11-07),

Related

Extract date mysql

as a very noob on mysql, I'm wondering how I can get my invoices, dated since more than 16 years.
I need a function that works at all time, so without specifying today's date.
I know it starts by
select extract(year from now()...)
the "..." being the rest of the function.
Here' the table structure
I expect the script to fetch all the invoices stored in the database, that are dated since more than 16 years
If you guys need more details I'll be glad to give.
Thanks !
To get the year 16 years ago:
extract(year from current_date - interval'16' year)
ANSI SQL compliant way, supported by MySQL.

Mysql query group by week with specific start and end

I searched stack overflow and have come so close yet have not found if this is possible.
I want to group a weekly query from 11:30 am Friday to 11:29 am Friday for each week.
adding days and hours only partially work. I need to keep this in a mysql query not coding in php, etc.
You need to give more information on your table structure and some sample date. If I have understood correctly then below is simple pseudo code which you can start use to start framing your requirement .
select something from table where date between 1:30 am Friday and 11:29 am
group by trunc(date).
Note :
- Format the date in where condition using to_Date.
- Week definition might be different in database so you need to manipulate.

How do I write the Criteria in Query Design to equal last month's data?

I've looked on a couple different forums and I'm unable to find what I need they all have it listed in SQL View, and that is NOT what I want. I would like to do this in the Query Design as it is much easier for me.
I simply would like to make a query to display certain parameters of the database I maintain. And those parameters would equal last month's data.
I previously was able to successfully make a query displaying all information for the past year but can't figure out how to display just this past months.
The past year Criteria:
>DateAdd("yyyy",-1,Date())
Since that worked I tried doing this but it would not work for me:
>DateAdd("mmmm",-1,Date())
I'm sure it's something simple that I'm just not seeing here. Any help or recommendations are welcome.
Referencing the link provided by Fionnuala I have come up with
>DateAdd("m',-30,Date())
The problem being is that it queries all results for the past 30 days from Today's date. I wish to display only data from October ! While this can be done easily. I don't wish to manually go in this query every month and change certain parameters. I would like it to be automatic so or next month December I click on the query and it displays all 30 days of November's data. And there is no manual process of going back in and changing any of the criteria.
In the Query Designer you can use a Criteria: like this
>=DateSerial(Year(Date()),Month(Date())-1,1) And <DateSerial(Year(Date()),Month(Date()),1)
The corresponding SQL statement is
SELECT Donations.*
FROM Donations
WHERE (((Donations.DonationDate)>=DateSerial(Year(Date()),Month(Date())-1,1)
And (Donations.DonationDate)<DateSerial(Year(Date()),Month(Date()),1)));
If it was run on November 18, 2014 then it would effectively be
SELECT Donations.*
FROM Donations
WHERE (((Donations.DonationDate)>=DateSerial(2014,10,1)
And (Donations.DonationDate)<DateSerial(2014,11,1)));
Notes:
This query should be sargable and take advantage of an index on the date field (if one exists).
In case anyone is concerned about "month wrap-around", the DateSerial() function takes care of that for us. If the query was run in January 2015 then the first WHERE condition would indeed be ... >=DateSerial(2015,0,1) but that's okay because it returns 2014-12-01.

Using MySQL to return row between to strings with date, but without year

I am currently working on a project in which I want to store commemorative days (like January 8th's World Leprosy Day) in a database. At this moment they're stored in a table which contains:
- an ID
- the date as varchar (stored European style, e.d. "8-01" for January 8th)
- length of the commemorative day (as some span multiple days)
- and the name
The reason I am storing the date as varchar is because the year is irrelevant, and I'm a bit reluctant to just store a year (e.g. 2013) in the database and truncate it.
But here's the problem: I can't seem to find a way to construct a query that will get the rows between dates. I think it's because the way the dates are stored in the database.
I already tried (given day = "8-01")
SELECT * FROM comdays WHERE date(day) BETWEEN date("1-01") AND date("20-01")
But to no avail.
Is there a way to get this thing going with strings? Or do I have to change the date column into a MySQL DATE format?
Thanks in advance!
If you really want to keep non standard date field in MYSQL you will need to use the following format 0108-> mmdd this format allows calculations.
It might also be worth reading the following answers to similar question Save day and month in database

to get date dynamically exceeding 24hrs

Iam writing a query by which i should get the contents from table which are not attended even after 24hrs of it is created .Can any one please tell me how to get the contents . Right now iam using
Created_time<'+DateTime.Now.addmin(-24)+'
But this is not working .Can any one please help me out
Thanks in advance for any answers
Use the date functionality in the database only, that will save you trouble in the long run. Use a query like:
SELECT * FROM table_of_interest WHERE datediff(curdate(), created_time) > 0
As for your original DateTime.Now.addmin(-24), I would expect that to be 24 minutes in the past, rather than 24 hours, but I don't know what language you're using so I might be wrong.