How to load data within date range on Qlik Sense? - mysql

I would like to load data within a defined date range on Qlik Sense.
When I load the data, I set it to be in the format below:
SET DateFormat='DD/MM/YYYY(WWW)';
I hope to use a where statement to limit the data where the column variable [Date] is within a date range.
However, the below statement placed after the LOAD columns FROM table statement did not work:
where [Date]<'30/11/2016(Wed)' and [Date]>'01/12/2015(Tue)'
May I know what is the syntax for

If you want to limit a date in MySQL to a range, using the date bounds of the range alone is enough, i.e.
WHERE date BETWEEN '2015-01-12' AND '2016-11-30'
Specifying the day of the week is redundant and unnecessary, because for example Novmeber 12, 2015 is always a Tuesday.
If your source date data has the format dd/mm/YYYY then you can use the STR_TO_DATE() function to parse into a date. After that, you can make the same comparison:
WHERE STR_TO_DATE(date, '%d/%m/%Y') BETWEEN '2015-01-12' AND '2016-11-30'

Related

Conditional formatting for current day date

I am just trying to getting my data to do a color fill if the date value equals today.
The data is coming from oracle:
=IIf(Fields!finishDATE.Value = Today(),"Yellow","Transparent")
This will not give me any errors nor will it do the function according to the expression. None of the data with the finish date equaling today highlights.
If today is 8/24/2021 it should look like this:
3/22/2021, 8/24/2021, 2/22/2021
As I'm not sure what format the data will come in from Oracle (I'm a MS SQL person) then this might be overkill but try this
=IIF (Format(Fields!finishDATE.Value, "yyyyMMdd") = Format(Today(), "yyyyMMdd"), "Yellow", Nothing)
All I'm doing here is comparing just the date parts of the date/datetime values.
Below is the output. The first column is the actual date column contents including a time, then for illustration only, the 2nd column shows it formatted to just the date part and the 3rd column show today() with the same format applied.
Finally, I used the keyword Nothing (SSRS almost equivalent of NULL) as this is the correct default value.

Specifying date range in a request in MySQL

I have a table with some info about trade goods, kinda logistics. It has a column called 'arriving_date', which contains the arrival dates in a format like this "30.06.2019".
Now I need to enter a request which displays only the goods which have not arrived yet, in other words which arrival date is > 30.06.2019. So I'm entering my request
SELECT *
FROM traffic
WHERE arriving_date > '30.06.2019'
But this request shows me just blank field. And I think I've already guessed why. Apparently it can't compare numbers in a format like that. But I'm not sure how should I make it compare dates then. Help is appreciated.
Assuming that arriving_date is just a string (and not an actual date)
SELECT *
FROM traffic
WHERE str_to_date(arriving_date, '%d.%m.%Y') > now()
OR arriving_date is null;
This will convert the arriving_date string into a date and compare it to the current date and time.
I also added a check for arriving_date being null (ie not set) in case it's set upon arrival.
Note that using a function on the value from a column makes all queries run full table scan. There is no way around that since your date format is as it is.
Thanks everyone for help!
I manage to solve my problem this way:
1. I changed arriving_date data type to 'date' (it was integer)
2. I rewrote dates from format 'dd.mm.yyyy' to 'yyyy-mm-dd', not sure if it matters.
3. final request looks like this:
SELECT *
FROM traffic
WHERE arriving_date > NOW()
It works perfectly now.
assuming that the arriving_date column is a porper date data type try convert the date string in a proper date
SELECT *
FROM traffic
WHERE arriving_date > str_to_date('30.06.2019', '%d.%m.%Y')
or if both date

How to separate time from datetimepicker vb.net

I have one datetimepicker which custom format MM/dd/yyyy h:mm tt
I have database and has a column "Date_Time" the value of the DateTimePicker is saved to the column Date_Time formatted like this MM/dd/yyyy h:mm tt
now i want to get the Time only not the entire value of datetimepicker just the hh:mm tt from the column Date_Time
SORRY FOR MY GRAMMAR
How about DateTime.TimeOfDay?
It returns the time that has elapsed since midnight (which is what h:mm tt stands for in your code).
Dim Time As TimeSpan = DateTimePicker1.Value.TimeOfDay 'Would return for example 3:14 PM
The answer above is right.
If you need to get time string, you can use also another way, which includes a formating:
Dim myTimeString = DateTimePicker1.value.ToString("hh:mm")
You can do that for any part of the DateTime value.
You are heading for a new problem. If you zero out the Date portion and store the result to a DateTime column, you will end up storing something like: 0001-01-01 16:43:12. A column defined as DateTime will always have a Date, as will a DateTime variable.
The first problem may be getting MySQL to accept a non-Date in a DateTime column. Using a column defined as DateTime(3), mine throws a generic fatal error exception trying to store just a TimeSpan to it:
cmd.Parameters.Add("#p3", MySqlDbType.DateTime).Value = DateTime.Now.TimeOfDay
cmd.ExecuteNonQuery()
If MySqlDbType.Time is used as the type, I get an exception that the time is an invalid value for the column...and it is.
If you manage to store it somehow, the next problem will be when/if you want to put that value back in a DateTimePicker: the minimum date you can enter is 1/1/1753 (first full year of the current calendar). So your DateTime var with the Date zeroed out wont work. You'll first have to restore the date portion, but the Date, Year etc are all readonly.
Solution 1
Define the column as Time(0) which will store hours, minutes and seconds. Use the value in the parens to specify fractional seconds, for instance Time(3) will also store milliseconds. When you read the data, store it to a TimeSpan.
Then in your UI use a different control, otherwise you have the same problem - adding some Date data to it to make it usable in a DateTimePicker
Solution 2
Use a DateTimePicker and a DateTime column, but just ignore the Date portion in your code. This will allow you to use what is in the Database as is with the control.
You can get the time selected with DateTime.TimeOfDay but storing and reusing it may be problematic.

Convert Date to a number in mysql (Like how a date converts in Excel)

What is the correct function to use when i want to convert a date to a number. Like when you enter a date in excel for example (now()) and then it will show the date but when you click on the number format it will show you a number.
I tried to use Unix timestamp but its not exactly the output i was looking for.
The date i entered is today's date
=now()
and the output i was hoping to get is
42146
what's the correct function to get this result in mysql?
Thank you
Microsoft Excel bases date serial numbers from Jan 1, 1904 or from Jan 1, 1900 (depends on the setting in the workbook.)
To generate a date "serial number" similar to what Excel uses, just calculate the number of days between NOW() (or whatever date you want to convert), and the base date. For example:
SELECT DATEDIFF(NOW(),'1900-01-01') AS excel_serial_date_1900
(You might need to add 1 or subtract 1 to get the exact same value that Excel uses, I've not tested that.) If your Excel workbook is using the 1904 based serial date, use '1904-01-01' as the base date in the expression.
Note: the DATEDIFF function returns integer number of days, operates only on the "date" portion, and doesn't include any fraction of a day.
Reference: https://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_datediff

How can I store the date to the table without a time stamp?

I am in a form, using Short Date format (I have tried General, Long, Medium) - each stores a time stamp along with the date in the table. like x/xx/xxxx hr:min:ss am/pm.
This should be so simple.
As noted in the comments to your question, values in Access Date/Time columns always have both a date and a time component. However, in most cases Access will display only the date part if the time is exactly midnight, so if you force the time to midnight when storing the value then it will look like a date-only value.
By changing the Date value to Integer you can hide the time portion of the Date and Time.
Example:
dValue = Now() shows Date and Time
dValue = Int(Now()) shows only the Date