Calendar control date not known (ASP.Net) - sql

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

Related

Cube Calculation - MDX - Compare Date to Another Date from Date Dimension

I am trying to create a calculation measure to compare revenue from one date to last year's equivalent date.
I have this "last year's equivalent date" stored in my date dimension.
So for example, my fact table of DailySummary has a measure of TotalRevenue and it is granular by date. If I wanted to show today's revenue (12/06/2019), the equivalent date from last year that is stored in the Date dimension would be 12/07/2018. I would want to show both those day's revenue side by side. I would then create other measures, like growth.
I am sure it is obvious, but if it helps, the DailySummary fact and the Date dimension are joined by the date, so today's date, not the last year equivalent.
Let me know if this doesn't make sense or if you need more information.
I think that you will need to use the PreviousPeriod MDX function.

add month to curent date in aqua data studio

I am trying to develop a report through aqua data studio by using SQL.I am trying to extract report of last month like counting the total number of new users in the last month. Date_Creation is the column when a user is registered in the system. I have tried DATEADD("MONTH",-1,Current_Date) but getting error "Month is invalid in context" .Any Solution/Suggestions?
DB2 doesn't use DATEADD for date arithmetic, you just, err easier to show.
SELECT *
FROM TABLE
WHERE DATE_CREATION > CURRENT DATE - 1 MONTH;
If you want to add a MONTH, why are you trying to "add" a "date" (which is what I assume DATEADD might mean)? What does it mean to add two DATEs together? I.e. what is the result of '2019-01-01' + '2019-01-01' ?!
Anyway, I digress. You can use ADD_MONTHS if you wish https://www.ibm.com/support/knowledgecenter/en/SSEPGG_11.1.0/com.ibm.db2.luw.sql.ref.doc/doc/r0053628.html
or, use the - 1 MONTH solution, which is just as good (if not better)

datepart in sql on year change

I am using datepart function in SP. It is used to compare week and year of specified date.
Now my query arise as new year starts. I have one table called 'Task' and it is storing tasks date wise. Now When I execute SP with DATEPART(YY,'2016-01-05') . It is giving proper 2016's data. But I execute it with DATEPART(ISOWK,'2016-01-05') , it is giving 2015's data also with 2016's data.
I want data from 28th dec,2015 to 2nd jan,2016. Data of the week. And I am not able get data of 1st and 2nd Jan in that. Please help me with this.
Thanks,
ISOWK return the week number
You are trying to get date from 2015-12-28 to 2016-01-02.
The week number of 2015-12-28 is 53 and 2016-01-02 is 53
If you already have your start and end dates decided then you could use a simple query as shown below to filter on date range.
When mentioning date string in your query make sure you stick to this format :yyyymmdd which SQL Server will automatically understand. You don't need DATEPART to get records between two dates.
Query for filtering on a date range
SELECT TaskID, TaskDescription
FROM Tasks
where TaskDate between '20151228' and '20160102'
Another query you can use for date range filtering
SELECT TaskID, TaskDescription
FROM Tasks
where TaskDate >= '20151228' and TaskDate <= '20160102'

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

Filtering rows based off of relation to date column

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.