Subtracting between two dates for total days - expression

i have three columns for Date In, Date Out, Total Days. If in Date In: 8/1/2011 and Date Out: 8/12/2011 Then the Total Days would be: 11 days. If Date Out is empty then Total Days = Current Date - Date In.
Problem: i cout get the total days if Date out is empty and using current date just fine, but getting total between date out and date in is giving me an error.
In the textbox in the reportviewer i have this expression:
=IIf(Fields!DateOut.Value=" "," ",Fields!TotalDays.Value)
The TotalDays is Current Date - Date In which i calculate in a stored procedure and just return the results.
I was thing of doing this but still i am getting an #Error in the textbox if i tried subtracting between date out and in if they are not empty.
=IIf(Fields!DateOut.Value=" ",DateDiff("d",Fields!DateOut.Value,Fields!DateIn.Value),Fields!TotalDays.Value)
Any suggestions.... Thanks

I know this is a little late, but i came up with the same issue. Here's what I did:
=CDate(Fields!DateOut.Value).Subtract(Fields!DateIn.Value).Days
Hope this helps!

Thanks for the info. Just wanted to share as I am not a programmer and this might be helpful to someone who is in my shoes that is required to write code.
I was able to create my formula from Answer 1. I had a requirement to have the Period End Date display the date 6 days prior. IE. EndDate = 06/24/2012 Field needs to display as 06/18/2012
=(CDate(Fields!EndDate.Value).AddDays(-6))

Related

Filtering from todays date, showing past dates

I followed advice on how to filter CDS records based on dates. I thought it was working last week, but now it's showing past dates. I am using powerapps and datasource is cds and I placing this into a gallery.
The formula which have been entered into the items field:
Sort(FirstN(Filter('Course schedule',End <= DateAdd(Today(), 70)),2),End)
Right now it's showing a record where End = 26/11. A past date. Plus a date in January 2022. However I have several dates between today and January. The expected view would be to see the 2 upcoming records that are closest to today's date. And not past dates...
In this picture we see the End-field showing 26th of november and January 21st.
The first is to understand why it's showing a past date and how to remedy it.
The second, what to add to sort it by end-date.
For clarification, 'Course schedule' is the table/entity I am referring to, End is the column/field inside of it that's chosen to filter from. It's a date type field.
Many thanks!
Ok, I think I have figured it out just by trying. Not sure why though:
Sort(
Filter(
'Course schedule',
End >= DateAdd(
Today(),
1
)
),
End,
Ascending
),
2
)```

Displaying date - three days in long format minus the year in Freemarker

looking for way to display the date in freemarker as "June 1", so long format minus the year. I also need to output the date minus 3 days. So the code that works is
${(.now?long - 259200000)?number_to_date }
but that displays the year as well (June 7, 2021)
I need to get rid of the year.
I figured it out. For anyone who is reading this in the future:
${(.now?long - 259200000)?number_to_date?string['MMMM dd']}
prints as
Current date, minus 3 days, without year. So for me rn :
June 7

Optional date and month in date field in Laravel

I have a Photo model that contains information about a historical photo, including date of photography. Often we do not know exactly which day the photo has been taken, but only the month or year. Is there some way to solve this without having three database fields for date, month and year.
date("m-Y",strtotime($date));
I think this could work. Let me know if it helped.
You can enter a date with a random day. It will cut it out.

Decimal places on dates, Crystal Reports

Good morning,
I'm currently working on a custom date for a label. It needs to read the last 2 numbers of the current year, followed by the number of day it is within the current year (8/3/2016 would be day 216). So if I were to print a label, the date on 8/3/2016 should read 16216. The following is the current code in the formula:
toText(CurrentDate,"yy") & DateDiff ("d", #1/1#, today) + 1
For reasons I'm unfamiliar with, this returns 16216.00. My question is how do I get rid of the decimal places with this being a text field?
If taken by themselves, toText(CurrentDate,"yy" returns 16 and DateDiff ("d", #1/1#, today) + 1 does return 216. It's only when concatenated that the decimal places appear. Is there a better way to do this?
I'm fairly new to using Crystal, so any help would be appreciated.
Thanks, guys.
You are looking for the Julian date. You have a couple of options
SELECT DATEPART(yy, #date), DATEPART(dy, #date)
SELECT RIGHT(CAST(DATEPART(yy, #date) AS char(4)),2)
The link below goes into much further detail
http://blogs.msmvps.com/robfarley/2009/03/25/converting-to-and-from-julian-format-in-t-sql/

combining date and time and changing it to GMT

I have read many answers for combining date and time and nothing worked so far. I am working in Oracle SQL developer version 3.1.06 and I am trying to combine date and time stamps together. Date is in format dd-mmm-yy. And time is in the following 3 formats-
1. 0348A-- meaning 3:48 am
2. 03:48:00
3. 228 -- meaning minutes from midnight, calculated as (3*60)+48.
And for all these timestamps, I want a query that gets me to this format --
mm/dd/yyyy hh:mm:ss .
I can change the dates and times to string and attach them, but then when I work in powerpivot I am not able to change them to the required format. So, I want to do it in the query itself.
I have already tried something like this-
1. CAST(deptdt as DATETIME)+CAST(time as DATETIME)
2. CAST(depdt AS TIMESTAMP(0)) + (depdt - TIME '00:00:00' HOUR TO SECOND) AS DATETIME
Please help!!

Resources