date conversion in SSRS - ssrs-2008

I have startdate and enddate as parameters in my report..
and in query I am checking condition
where (date BETWEEN (#BeginDate) AND (#EndDate))
the date field in database is in '2012-06-18 00:00:00.000' format.
so do i need to do any conversions in the query..
I m getting no results in the report..
I also tried where (CONVERT(varchar, date , 101) BETWEEN (#BeginDate) AND (#EndDate))
still no results.
Please advise.

If the date field only ever contains the date part (time part is always set to zero) then adding 1 day to the end date will return everything for '2012-06-18'.

Related

Checking if today's date is in between the given start date and end date

The code is written in postgresql and run in pgadmin 4.
I am trying to get the id from the pricing table if the current date lies in between the given start date and end date.
I am trying to get the id from the pricing table if the current date lies in between the given start date and end date.
select id
from pricing
where current_Date between start_date>=date '2022-10-19' AND end_date<=date '2022-10-20';
The error raises
operator does not exist: date >= boolean LINE 3: where
current_Date between start_date>=date '2022-10-19'...
Your where condition is essentially someDate between someBoolean and someOtherBoolean, which confuses compiler. Use just this:
where current_Date between date '2022-10-19' AND date '2022-10-20'
between only expects the values:
select id
from pricing
where current_Date between '2022-10-19' AND '2022-10-20';

Reading weird date format in hive

I have a column which contians date as string but in many formats like - dd/MM/yy, dd/MMM/yyy .. etc etc. And I am using the following code to convert all strings to one specific date format (yyyy-MM-dd) in hive :
select
from_unixtime(unix_timestamp('31/02/2021','dd/MM/yyyy'),'yyyy-MM-dd')
but this gives me 2021-03-03 in HIVE.
Is there any other way to identify such invalid dates and give null.
Assume, you recognized format correctly and it is exactly 'dd/MM/yyyy' and date is invalid one '31/02/2021'.
unix_timestamp function in such case will move date to the next month and there is no way to change it's behavior. But you can check if the date double-converted from original string to timestamp and back to original format is the same. In case it is not the same, then the date is invalid one.
case
-- check double-converted date is the same as original string
when from_unixtime(unix_timestamp(date_col,'dd/MM/yyyy'),'dd/MM/yyyy') = date_col
--convert to yyyy-MM-dd if the date is valid
then from_unixtime(unix_timestamp('31/02/2021','dd/MM/yyyy'),'yyyy-MM-dd')
else null -- null if invalid date
end as date_converted

Crystal Reports: using date from the datatime field as a parameter

I am working on a report that I need to add a date range parameter. The field that I need to use in the datetime field, and I need to use the date portion from the field. I tried using the following, but the report returns no result.
cast(StartDateTime as date) between {?StartDate} and {?EndDate}
For the time being, I am using the Select Expert to sort the date range, but I have to manually enter the date in 'yyyy-mm-dd' format. Is there a way to set up the parameter, so that I can use the calendar to choose the dates?
I recommend to use one parameter field and set it to range and date instead of two.
With this you can use easily this formula:
{StartDateTime} = {?Parameter}
If you set the Parameter to Date instead of DateTime it will automatically check with the start of the day for the first range and the end of the day for the last range.

TSQL Between 2 dates or >= and <=?

Morning experts. I have a very simple query that I can not seem to get working as it should.
I have a table that has invoiceNumber, CustNum, Datetime, and Grand_total
I want to pull all transactions between a set of dates in this example all transactions between 4/10/2014 and 4/23/2014. I was using:
SELECT Invoice_number
,CustNum
,DATETIME
,Grand_Total
FROM invoice_totals
WHERE custnum = '10014877'
AND DATETIME BETWEEN '2014-04-10'
AND '2014-04-23'
ORDER BY DATETIME DESC
I just realized if there are any dates on 4/23 that this does not show them.. I have tried to substuite using:
WHERE custnum = '10014877'
AND DATETIME >= '2014-04-10' AND DATETIME <='2014-04-23'
But it is still giving me the same results (ignoring any transactions that occured on 4/23)
the last record pulling up has a datetime stamp of 2014-04-22 12:26:08.000. There ARE 2 transactions on the 23'ed I am trying to include.
Thank you very much.
The part:
AND DATETIME <='2014-04-23'
is actually(according to TSQL):
AND DATETIME <='2014-04-23 00:00:000'
So you're quering from midnight and missing all the transactions from 00:01 to 23:59 on the 23rd.
Try:
AND DATETIME <='2014-04-23 23:59:999'
Or
AND DATETIME < '2014-04-24'
Both should include all the transactions for the day of the 23rd.
If you're working with continuous data, such as datetimes, it's usually better to switch to using a semi-open interval - an inclusive start date and an exclusive end date. Exclusive end dates are usually easier to calculate:
WHERE custnum = '10014877'
AND DATETIME >= '20140410' AND DATETIME <'20140424'
I've also switched to a safe, unambiguous date format.
The alternative, using <= or BETWEEN (which is just shorthand for a pair of >= and <= comparisons, so your two queries were identical) requires an inclusive end date. Which depending on the exact data type you're using may be 2014-04-23T23:59:59.997 or 2014-04-23T23:59:59.9999 or any number of other possibilities - if you get it wrong and overspecify the value, it'll get rounded to be 20140424 and then an inclusive comparison is incorrect.
And even if you get it right today, it's a pain to find all usage of this pattern if the data type of the column changes later.
BETWEEN is inclusive with respect to the boundaries.
However, I'm guessing that the type of your (poorly named) DATETIME field is .. DATETIME, so in the comparison, the date '2014-04-23' gets converted to a DATETIME as follows: '2014-04-23:00:000'. Thus, all records with DATETIME greater than that first moment on 04-23 are rejected.

How do extract just the date (without the time) from an integer field in SQLite3?

I have a small SQLite3 DB that has an integer field called "dt". It stores date and time.
I am having trouble extracting just the date from the field. However, doing a "select date(dt) from log2" returns nothing. I've tried strftime() as well, but no cigar.
Please help. This is driving me insane.
Thanks.
if the Date in dt is wellformed then the result shoeld be the date from a datetime column
select date('2011-01-01 23:55:55');
should receive
2011-01-01
but
select date('2011-01-01 23:55:5');
would receive nothing
so the dt coloum have to be wellformed