Filtering rows based off of relation to date column - vba

I am trying to find a good way to filter data based off of the date column (Column I in my actualy spreadsheet). I can copy the rows and all of that to another sheet just fine, but the date thing is new to me. Basically I need to know how to filter based on three situations:
If the current date is within 3-6 months of the date in Column I;
If the current date is within 0-3 months of the date in Column I;
If the current date is past the date in Column I.
Thank you for any assistance.

Sounds like you want to use the DATEDIFF VBA function. Here is an example: http://www.techonthenet.com/excel/formulas/datediff.php.

In addition to DateDiff you can use:
Date()
Year()
Month()
Day()
Functions to determine this information.

Related

How to find the weekday from the date for an entire column of dates

I know that you can use the DATEPART(), FORMAT(), WEEKDAY() functions to find the weekday of a single date, but I need to use these functions to create a new column that finds the weekday for an entire column of dates in date_dim_id. How do I do this?
Below is my date_dim_id column. I want to add a column beside it that tells me which weekday each date is.
Try this:
select date_part(dow, '20210805') as dayoftheweek

SQL - filter values based on month & date

I'm currently strugeling to get something done.
I needed only the rows where the date is between a certain date and month.
Example show only the rows where the date is between 01/05 (DD/MM) and 08/07 (DD/MM) the date can be found in the table tasks within the field information.
The year can't make any sense, but the results may only between those two dates in that year.
I've tried:
BETWEEN (TO_DATE ('01/05','DD/MM') AND (TO_DATE('08/07', 'DD/MM')
EXTRACT (DD/MM) from information.
none of those are working for me, I hope that someone of you can help me to figure this out!.
Thanks!
You seem to want to disregard the year. If so, then I would recommend:
TO_CHAR(datecol, 'MM/DD') BETWEEN '05/01' AND '07/08'
In order for BETWEEN to work in this case, you need the format in the order of MM-DD.
If you want this for a particular year, then use direct date comparisons:
datecol >= DATE '2018-05-01' AND
datecol < DATE '2018-07-09' -- note this is one day later
Oracle dates have a time component, so you need to be careful when making comparisons.

Calendar control date not known (ASP.Net)

Sometimes we have dates that are unknown, eg: We won't know the date but just the month and year.
eg: --/Dec/2015, the date is not known? How do we accept these kind of values?
Any ideas on can this be stored on SQL Server database?
I would store it as a date in the database. Because with a date you have benefits like:
Calculation function like DATEADD and DATEDIFF.
You will be able to sort on one column
Index will be one column
When you need to get the year and the month. You just use MONTH and YEAR

Get the month and year now then count the number of rows that are older then 12 months in SQL/Classic ASP

I know this one is pretty easy but I've always had a nightmare when it comes to comparing dates in SQL please can someone help me out with this, thanks.
I need to get the month and year of now then compare it to a date stored in a DB.
Time Format in the DB:
2015-08-17 11:10:14.000
I need to compare the month and year with now and if its > 12 months old I will increment a count. I just need the number of rows where this argument is true.
I assume you have a datetime field.
You can use the DATEDIFF function, which takes the kind of "crossed boundaries", the start date and the end date.
Your boundary is the month because you are only interested in year and month, not days, so you can use the month macro.
Your start time is the value stored in the table's row.
Your end time is now. You can get system time selecting SYSDATETIME function.
So, assuming your table is called mtable and the datetime object is stored in its date field, you simply have to query:
SELECT COUNT(*) FROM mtable where DATEDIFF(month, mtable.date, (SELECT SYSDATETIME())) > 12

Setting date range in queries

I would like to add a condition in my query to filter records which has a date falling under current month. How can I achieve this? I tried to use clj-time to retrieve the current month and match it along with the DB field. But that didn't give me any luck.
Actually, it's pretty simple to determine the current month using clj-time:
(month (now)) ; number from 1 to 12
But, since you're trying to query a database, you should be interested with the beginning of the current month:
(let [t (now)]
(date-time (year t) (month t)))
This code will return you a valid DateTime object, corresponding to the beginning of the current month. You can use this object t query your SQL database:
(select objects
(where {:created [> start_of_the_current_month]}))