SQL Query to pick data from a certain time range - vb.net

I have two fields in my DB.
1) Invoice_Date and Invoice_Time
They recored date and time from my invoices.
I want to pick data under two queries:
1)Using From_Time DateTimePicker and To_Time DateTimePicker (they display as 19:20:18 PM)
Here I want to pick data for say between 13:10:12 PM to 18:10:20 PM, no matter what date it is.
2) Secondly I want data for a specific data range (from datatimepickers) to specific time range (time datatimepickers)
Please advise how to do it.
I tried:
Where InvTime between #Time1 and #Time2
But it did not generate any data, while data is there for the given time range.
Please help.
Thanks

I think if I understand you correctly you want you want to find all invoices between a start and stop time based on your invoice time. I will assume the invoice time is a date time field that may have different date values.
Where CONVERT(DATETIME(CONVERT(CHAR(5),invoice_time)) BETWEEN #StartTime AND #StopTime
You could also do the same conversion to your start and stop time. The key here is that all the datetime values you are comparing have the same date Since all we care about is time the date will just be the default.

Related

subtract current_time from timestamp in PostgreSQL

I have a table where each entry has a timestamp. I am using this timestamp to calculate e.g. the number of entries per day in the last week. However, I do not really care whether the results that I get represent a particular day. The actual goal is to divide the entries into 24h-bins that I can compare and see whether there has been any significant change over time. Furthermore, since I am working with almost real-time data, I would like to perform this analysis at any time and also take into account the most recent entries. If I would just group the entries per day and perform the query in the middle of the day then I would get a not particularly insightful result for the current day.
My idea was now to subtract the current time from the timestamp of the entries and then do the grouping by days. This way I could get 24h-bins each of which represents a full 24h period and the youngest one also contains the most recent entries.
Something like this:
created_on - current_time
Of course I cannot subtract a time from a timestamp. Is there a way to convert current_time into an interval? Or is there an entirely different approach that is easier?
Is there a way to convert current_time into an interval?
Yes, just cast it.
Note that the use of current_time is discouraged so it's better to use localtime instead.
You can do:
created_on - localtime::interval
But it seems you might just want to set the time part of the timestamp to 00:00:00 which you can do by using date_trunc()
date_trunc('day', created_on)

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.

Hive - How to query a unix timestamp to identify yesterday's values?

I have the following problem to solve. I have a hive table, that store events, and each event timestamp is stored as unix timestamp (e.g. 1484336244).
Every day I want to run a query that fetches yesterdays events.
How could I form this query in Hive?
So for example, today is the 9th February, I want to get only the events that occurred on the 8th February.
Subtract one day from current_date and compare it with the column converted to yyyy-MM-dd format.
date_add(current_date,-1) = from_unixtime(colName,'yyyy-MM-dd')

Starttime and endtime

i have paramters fields as starttime(=DateAdd("d",-1,now())) and endtime (now()) and status( as dropdown ex:running,succededtec,.) in my report.... when i run the report with the whole timestamp it is working as expected but if i give only date in both the fields without time then am not getting last one days data( for example if starttime is 6/14/2017 and endtime is 6/18/2017 am getting data till 6/17/2017 only) .....one more scenario is when I have no endtime (like status is running we have no endtime) then am getting that.Can anyone help me out.
Thanks
The time defaults to 00:00:00 if not included.
So basically when you're comparing say
06-18-2017 07:52:11 <= 6-18-2017
you're actually comparing
06-18-2017 07:52:11 <= 6-18-2017 00:00:00
Since the time defaults to zero, and you will never get any 6-18 results returned unless they happened at exactly midnight. Set the timestamp in your compare, or use 6-19 as your compare date instead (with the risk of including a random record that happened at exactly midnight on 6-19).

Format date in Values for a Range (Gant) Chart SSRS 2008 R2

I have a date column in which the dates are re-curring every year. I'm only interested in the month really, but I can't just put the month number as the high and low value for the gant chart. Is there any way I can format the column? Any suggestions would be awesome.
The gant chart currently is taking the whole date and is working fine, but like I said it goes out to the next year.
Figured it out. So the DATECOLUMN I had was formated as such:
Example: 2013-01-01 00:00:0.000
In order to put in the GANT(RANGE) CHART in the series property, under values, I formated the Top Value and Low Value as =MONTH(DATECOLUMN) using the expression option.
Then for the Horizontal Axis Properties I set the Interval to 1 and Interval Type to Number. And There you have it Monthly time spans with only the Months 1 - 12 showing.
I must also note that I only had one time recorded. So I just did Top Value as: DATEADD(MM,1,DATECOLUMN) In Order to get the right time span in my dataset Script.
Which date format would u like to display in your chart.
If (month with year) like 'Sep 2013'
use this date format for the same.
SUBSTRING(CONVERT(VARCHAR(11),getutcdate(), 113),4,8)