Crystal Report Date Range Report - crystal-reports

i'm using Crystal Reports and I have an output like this (group by day):
(This output calculation is from 00:00 to 23:59 each day..)
Date (dd/mm/yyyy) Weight
-----------------------------------------
01-01-2013 4000
02-01-2013 3000
03-01-2013 6000
04-01-2013 5000
How can I make it by time range like 01-01-2013 6:00AM to 04-01-2013 6:00AM and the output still as per day:
(I pretend the half of current day + half of the next day)
Date (dd/mm/yyyy) Weight
-----------------------------------------
01-01-2013 3500 ( =half of 01-01-2013 and 02-01-2013)
02-01-2013 4500 ( =half of 02-01-2013 and 03-01-2013)
03-01-2013 5500 ( =half of 03-01-2013 and 04-01-2013)
04-01-2013 2500 ( =half of 04-01-2013 and so on..)
Thanks,

You'd want to check the time whether it's before or after 12:00 noon. If it's 11:59:59 or less, add it to the previous day. Anything after, current day. Create a formula using something like this
IF TIME({yourdatetime}) <= TIME(11,59,59) THEN
DATE({yourdatetime}) - 1
ELSE
DATE({yourdatetime})
Then group by the formula and format the group header for just the date.

Related

Return number of days passed in current quarter

How can I get the number of days passed in the current quarter?
For example, if today is 1/2/2021, it will return 2.
If today is 2/5, it will return 36.
If today is 4/2, it will return 2.
Use date_trunc() to get the start of the quarter and subtract dates:
WITH cte(day) AS (
VALUES
(date '2021-01-02')
, (date '2021-02-05')
, (date '2021-04-02')
)
SELECT day
, day - date_trunc('quarter', day)::date + 1 AS days_passed_in_quarter
FROM cte;
day | days_passed_in_quarter
------------+------------------------
2021-01-02 | 2
2021-02-05 | 36
2021-04-02 | 2
+ 1 to fix off-by-one error as you clearly want to include the current day as "passed".
Always use unambiguous ISO 8601 date format (YYYY-MM-DD - 2021-02-05), which is the default in Postgres and always unambiguous, or you depend on the current datestyle setting (and may be in for surprises). Also avoids misunderstandings general communication.
Related:
PostgreSQL: between with datetime

How to convert respectively four column to date formatting at MATLAB?

Excel file(104976x10) includes large data.
A column: Time (unit year)
B column: Year
C column: Day of the year
D column: Hour
E column: Minute
and others including values
I would like to convert column which begins with B column until E column to date format like 'dd/mm/yyyy HH:MM'.
Example for the data:
1998,41655251 1998 152 1 0 12,5 12,0 11,8 11,9 12,0
I would like to do date instead of 2-th, 3-th, 4-th and 5-th columns.
1998,41655251 01/06/1998 01:00 12,5 12,0 11,8 11,9 12,0
or
1998,41655251 01/06/1998 01:00 1998 152 1 0 12,5 12,0 11,8 11,9 12,0
Welcome to SO.
Matlab has two types of date-format:
datetime, introduced in 2014b.
datenum, introcuced in long ago (before 2006b), it is basically a double precision value giving the number of days from January 0, 0000.
I think the best way is to use datetime, and give it the year, month, day, hour and minute values like this:
t=datetime(1998,0,152,1,0,0)
t= '01-May-1998 01:00:00'
As you can see the days automatically overflow into the months. But I end up 1st of may, not 1st of june like in your example.
to change the format:
t.Format='dd/MM/yyyy hh:mm'
t= '01/05/1998 01:00'
to convert it to a string, you can simply use string(t)
This is an example that combines the above functions to read an xlsx file and writes a new one with the updated column.
data=xlsread('test.xlsx');
S = size(data);
t = datetime(data(:,2),0,data(:,3),data(:,4),data(:,5),0);
t.Format='dd/MM/yyyy HH:mm';
data2=num2cell(data(:,1));
data2(:,2)=cellstr(string(t));
data2(:,3:S(2)-3)=num2cell(data(:,6:end));
xlswrite('test2.xlsx',data2);

PostgreSQL: Date Difference with fractions

SELECT cu.user_id, cu.last_activity, cu.updated_time,
DATE_PART('day', cu.last_activity - cu.updated_time), to_char(end_date - start_date, 'DD.HH24')
FROM stats.core_users cu
WHERE cu.user_id = '117132014' or cu.user_id = '117132012';
Get the result like:
117132014 2017-12-11 10:34:51.349905 2017-12-09 12:00:38.503518 1 01.22
117132012 2017-12-11 05:18:20.312283 2017-12-08 15:46:51.914085 2 02.13
Is is feasible to get the day difference with fractions like 1.91 days in the first case, instead of 1 days and 22 hours, to be more precise and easier to fit in a machine learning model?
date_part() does what it's name says: it returns one part of several elements from a date, interval or timestamp. In your case it's one part of an interval (because timestamp - timestamp returns an interval).
If you want the result as a fraction, you need to extract the seconds of the interval and then divide that by 86400 (which is the number of seconds in a day)
extract(epoch from cu.last_activity - cu.updated_time) / 86400

Qlikview - Data between dates; filter out data past or future data depending on selected date

I've seen threads where the document has Start Date and End Date "widgets" where users type in their dates, however, I'm looking for a dynamic solution, for example on the table below, when I select a date, say "1/1/2004", I only want to see active players (this would exclude Michael Jordan only).
Jersey# Name RookieYr RetirementYr Average PPG
23 Michael Jordan 1/1/1984 1/1/2003 24
33 Scotty Pippen 1/1/1987 1/1/2008 15
1 Derrick Rose 1/1/2008 1/1/9999 16
25 Vince Carter 1/1/1998 1/1/9999 18
The most flexible way is to IntervalMatch the RookieYr * RetireYr dates into a table of all dates. See http://qlikviewcookbook.com/recipes/download-info/count-days-in-a-transaction-using-intervalmatch/ for a complete example.
Here's the interval match for your data. You'll can obviously create your calendar however you want.
STATS:
load * inline [
Jersey#, Name, RookieYr, RetirementYr, Average, PPG
23, Michael Jordan, 1/1/1984, 1/1/2003, 24
33, Scotty Pippen, 1/1/1987, 1/1/2008, 15
1, Derrick Rose, 1/1/2008, 1/1/9999, 16
25, Vince Carter, 1/1/1998, 1/1/9999, 18
];
let zDateMin=37000;
let zDateMax=40000;
DATES:
LOAD
Date($(zDateMin) + IterNo() - 1) as [DATE],
year( Date($(zDateMin) + IterNo() - 1)) as YEAR,
month( Date($(zDateMin) + IterNo() - 1)) as MONTH
AUTOGENERATE 1
WHILE $(zDateMin)+IterNo()-1<= $(zDateMax);
INTERVAL:
IntervalMatch (DATE) load RookieYr, RetirementYr resident STATS;
left join (DATES) load * resident INTERVAL; drop table INTERVAL;
There's not much to it you need to load 2 tables one with the start and end dates and one with the calendar dates then you interval match the date field to the start and end field and from there it will work the last join is just to tidy up a bit.
The result of all of that is this ctrl-t. Don't worry about the Syn key it is required to maintain the interval matching.
Then you can have something like this.
Derrick Rose is also excluded since he had not started by 1/1/2004

Find the end date of a quarter given a date

I have the end dates of each quarter as the PK for a table, and I need to compare a date to see which quarter-ending value would be used in a calculation.
The Table looks like:
EndingDate Value
12/31/2012 $1,000
For example, given 3/1/2013 I would need to return 12/31/2012 and use that date to retrieve the $1,000 value.
Does anyone know what to use in MS Access 2007 to perform this? I tried:
DATEADD(dd, -1, DATEADD(qq, DATEDIFF(qq, 0, DATEINQUESTION), 0))
The calculation always uses the previous ending quarter's date, and the value associated with that date.
One way to do it would be with a combination of DMax() and DLookup(). For sample data in a table named [EndingBalances]
EndingDate Value
---------- -----
2012-09-30 900
2012-12-31 1000
2013-03-31 1100
2013-06-30 1200
2013-09-30 1300
2013-12-31 1400
the expression
DMax("EndingDate","EndingBalances","EndingDate<#2013-03-01#")
would return the date
2012-12-31
and therefore the expression
DLookup("Value","EndingBalances","EndingDate=#" & Format(DMax("EndingDate","EndingBalances","EndingDate<#2013-03-01#"), "yyyy-mm-dd") & "#")
would return the value
1000
I used this solution and it worked for me:
Format(DateAdd("s",-1,DateAdd("q",DateDiff("q","1/1/1950",Date()),"1/1/1900")),"Short Date")
It works so far..