how to take off time in date time tabular model - tsql

I have a date dimension table and I have a Date column in that table it has datekey, fulldatekey, Date, DayofMonth, Dayofyear, month, ect. the Date column only has yyyy-mm-dd, but when I bring it into my tabular cube model it appends a 12:00:00 A.M time to the end of it. I was wanting to know how do I remove the time to only have the date. I am building a tabular cube in ssdt to bring into power bi

According to this Microsoft site,
In contrast to Microsoft Excel, which stores dates as a serial number,
PowerPivot date functions always return a datetime data type. However,
you can use formatting to display dates as serial numbers if you want.
From my "limited" experience, you can change the date formatting in one column, but when you reference it from another column, it will once again include the 12:00:00 AM time as part of the date when it displays in the new column. I assume this is because, as Microsoft says in that website,"PowerPivot date functions always return a datetime data type."

Edit Query -> Transform Tab -> Choose Data Type
That's my best guess.

Related

ExtJS Bug when selecting date from datefield

I have a:
Field in my store as date with dateFormat set to 'Y-m-d'
Column in my grid (datecolumn) - format set to 'Y-m-d'
Editor on Column (datefield editor) - format set to 'Y-m-d'
Postgresql Table with a date column (Note, not a timestamp or timestamptz, but date)
I have data that comes into the store from Postgresql like:
{
mydatefield: "2021-07-30"
}
Now, the date do dispay is 100% correct in the grid. Problem comes in when I select a new date, through the datefield editor, let's say
2021-07-31
The moment it saves back to the server it passes:
mydatefield: '2021-07-30T22:00:00.000Z'
and the server saves it wrong as '2021-07-30' and the grid refreshes back to 2021-07-30.
We are on South African Standard Time (+2) Do not know if it something to do with Daylight Saving
So, to recap. It does not matter what date I select, it keeps saving a day less than the day I selected.
The date it's saving is in UTC, which is the timezone you ought to be using on your server(s) and database(s) - that's a good thing as it removes timezone related info and allows dates to be localized to any timezone.
When you transmit date values over the wire between the server and the browser, make sure you're using RFC-8701 formatted strings (what you get when you call new Date().toJSON() in JavaScript). Then you won't have to worry about timezone issues, as RFC-8701 dates are always in UTC. The browser will take care of transforming dates to local time - just call new Date(myRfcDateString).
More info: Storing date/times as UTC in database
Use convert method of store to process data for date column before storing it in store data. Then the store data will be submitted to server in proper format.
There was similar question asked, links below -
Question - Datefield in grid editor
Fiddle - https://fiddle.sencha.com/#view/editor&fiddle/2e0a

How to convert a specific text string to today's date in Power BI

I have a table with a column called that contains text. Most of the values are years. However, some have the value "present" to represent groups that are still currently active. I want to convert those values to today's year, and convert the column type to date (specifically year type). I want to avoid creating a new column if possible.
Please see below for the DAX language that worked.
= Table.ReplaceValue(#"Extracted Year2",null,DateTime.LocalNow() ,Replacer.ReplaceValue,{"Disbanded"})

Data stored as DD/MM/YYYY in table, but querying in DD/MM/YYYY doesn't work for all dates MS Access 2016

There are probably many questions that are asking about date formats, but I haven't found anything like this.
I have a table, called t_birthday. t_birthday has a field called "DayOfMonth" which currently stores the data in a dd/mm/yyyy format. Lets say the record I have has the Date of 01/12/2016 (Dec 1, 2016).
Now, if I create a query using the "Query Design" option in the Create tab, I select my table t_birthday. For the field option, I select DayOfMonth. In the criteria option, I put =#01/12/2016#. When I click Run, it queries the database and returns the record with that date successfully.
However.. If I check the SQL generated from this Query Design, it is this:
SELECT t_birthday.DayOfMonth
FROM t_birthday
WHERE (((t_birthday.DayOfMonth)=#12/1/2016#));
If I try copy and pasting the DayOfMonth value from the table into that query, it wouldn't work. Notice how the format in the query is mm/dd/yyyy, but in my table it's still dd/mm/yyyy. I never touched any of the date formatting options in my table, or even on my computer. When I actually create this record using a form, I have a date picker which is in the form of dd/mm/yyyy as well.
Questions:
In the query design, when I specify criteria in dd/mm/yyyy, why does it generate sql in the form of mm/dd/yyyy?
I can only query dates using dd/mm/yyyy format if the day number (1-31) is 13 or above, OR if the month value and the day value are the same (October 17, Jan 1, March 3, November 11, December 12, etc). mm/dd/yyyy still works for those dates previously mentioned. I can't query dates like November 7th, Feb 3rd, August 4th, etc using dd/mm/yyyy though. How do I get around this problem? I store the dates, and I use the values directly from the table as conditionals in my queries. I shouldn't have to alter my date value in order to use them.
Why can I write an SQL statement for dates with the day number above 13 in dd/mm/yyyy format or mm/dd/yyyy format? E.g., the WHERE clause can look like: WHERE DayOfMonth=#13/06/2018 or WHERE DayOfMonth=#06/13/2018 and it still returns the same record? Why does access not enforce a specific format?
EDIT:
Currently I run my query in VBA and return it into a recordset using the following:
Dim bdayRecords As RecordSet
Dim sql As String
sql = "SELECT t_birthday.DayOfMonth"
sql = sql & " FROM t_birthday"
sql = sql & " WHERE (((t_birthday.DayOfMonth)=#" & rs("DayOfMonth") & "#));"
bdayRecords = CurrentDb.OpenRecordset(sql)
Where rs in the where clause was a previous recordset with a date value stored in "DayOfMonth". The rs recordset retrieved the date value from a different table in the exact same way bdayRecords was populated.
bdayRecords won't find the records with the date values matching the criteria explained before.
Use a properly formatted string expression for the date value retrieved:
sql = sql & " WHERE t_birthday.DayOfMonth = #" & Format(rs("DayOfMonth").Value, "yyyy\/mm\/dd") & "#;"
The ISO sequence yyyy-mm-dd works everywhere, so make it a habit to use that.
SQL always uses mm/dd/yyyy. That's not dependent on how you format it.
You never actually store a date in a certain format. You display a date in a certain format. All dates in Access are stored as a double-precision floating number containing the number of days elapsed since 30-12-1899, with fractions as time. How dates are formatted has no influence whatsoever on your SQL statement
Always use either mm/dd/yyyy or yyyy-mm-dd in your SQL. VBA only takes mm/dd/yyyy.
However, Access is opportunistic when working with clearly invalid dates, such as 13/1/2018. Because no 13th month exists, it parses it as the 13th of january, even though it's not a valid date.
If you're using values from other queries, there shouldn't be any problems, since the values never get cast back and forth to strings. You only get in trouble when casting a date to a string and then back to a date, which is not something you should do in queries, ever.
To avoid casting back and forth between strings, you can either refactor your code to a single query instead of retrieving a value from a recordset and inserting that value in a string SQL statement, or use parameters, which allows you to use the date value directly in an SQL statement.
For explanations why these design choices are made, ask Microsoft, they wrote the program. This is just how it works.

db2 getting business dates between given dates

I have a table called "Publicholidays" where in dates are stored as Varchar.
My query should fetch all values from say table xxxx between the user selected dates that exclude the weekends(sat,sun), public holidays. I am new to DB2 so can anyone suggest me ideas please
Note: in DB dates are stored as String.
Mistake #1 - Storing dates as strings. Let's hope you have at least stored them YYYY-MM-DD and not MM-DD-YYYY.
Mistake #2 - Instead of a "Publicholidays" table, you need a Calendar (aka Dates or date conversion) table. It should have a record for every day along with a few flag columns BUSINESS_DAY, WEEKEND, PUBLIC_HOLIDAY. Alternatively, you could have a single DAY_TYPE column with values for business day, weekend and holiday. You'll also want to have a STRING_DATE column to make conversion between your string date and a true date easier.
Google SQL Calender table and you'll find lots of examples and discussions.
Lastly, strongly consider fixing your DB to store dates in a date column.

Approximate date column

One of my customers would like to have a custom date column, where he could store the year only, a combination of month and year (without the day), or a classic date with day, month and year.
It should be possible to use this field for sorting the data. A "month-year" date should be considered as "01-month-year" for the sort, and a "year" date should be treated as "01-01-year" for the sort.
I could imagine two solutions to that:
Store the date in the standard "day-month-year" format, and keep in a separate column how the date was entered ("year", "month-year", "day-month-year"), so the approximate date can be displayed exactly how it was entered.
Use some sort of custom date column in the postgresql database.
Has anyone experience with that?
You could use date-time functions to extract date components. I don't think it has any sense to create additional columns. Also, some databases allow to create indexes by functions.