I have a Form and I want to calculate the remaining days for a warranty.
Below here are some similar with me but not meet my full requirement as they only calculate remaining without updated days.
Difference between two date/time fields - Lotus Notes
So, below is the function I have tried. For field1, I'm using #Today. For field2, I'm using #Modified. But if I use #Modified, it will set a date as last day I modified the document. I check example from https://www.ibm.com/support/knowledgecenter/en/SSVRGU_8.5.3/com.ibm.designer.domino.main.doc/H_EXAMPLES_CREATING_A_FIELD_TO_DISPLAY_DATES_AND_TIMES.html they use #Created as when document creates and #Now as today date.
Field1() will set today date and will update every day.
#Today
Field2 will be set by the user.
#Modified
Field3 will show the remaining days.
#Abs(#Integer((PDateEnd - PCurrentDate) / (86400)))
I want to display the remaining days with update days. For example, today 25/03/2019 to 27/03/2019 is 2 days. When the day update to 26/03/2019 to 27/03/2019 is 1 day. I am trying to make one field with update day and another field set the last day. Please suggest anything. Thank you in advance.
I take the answer from Torsten Link and umeli.
I set the field to Computed for display as it computes on Open of a document in read mode. Because I only use #Function for the field and not using any agent.
As I set as below to get the difference of two dates:
Field1 (set as computed)
#Today
Field2 (set as editable because I want the field to be edit)
#Modified
Field3 (set as computed for display as it only for read mode) and there are two method.
#Abs(#Integer((PDateEnd - PCurrentDate) / (86400)))
and
#Abs(#Integer((CurrentDate - DateCreated) / (60 * 60 * 24)))
If you do not want to set #Today, you can set field1 as "date1" and field2 as "date2".
And for field3 you can set as "(date2-date1)/86400"
Related
In my program, I have a data grid view. I make some amounts due for payment today. I made a display of the amounts that are due and have not been paid (late) I want a code that displays the dates less than the current date of the day I tried that following code but it only fetches the lower days and does not look For the month or year if it is greater or not than the current day's date
tbl = db.readData("SELECT * from Payments where date_batch < CONVERT(varchar(50),GetDate(), 103)", "");
DgvSearch.DataSource = tbl;
The problem with the previous code is that it doesn't fetch the date lower by day, month and year.
Fetches the date less than the current date in terms of day only I want in terms of day, month and year
Ok, so I'm going to assume date_batch is a VARCHAR(10) or similar and contains data like:
28/12/2021
29/11/2021
30/08/2021
31/12/2021
As you can see these "strings that look like dates to a human" are in order. They are not in date order, they are in alphabetical order. Big difference - SQLServer sorts strings alphabetically. When you ask for strings "less than x" it uses alphabetical sorting rules to determine "less than"-ness
Don't stores dates in a string. SQLServer has several date specific datatypes. Use them.
The following process will dig you out of the hole you've dug yourself into:
ALTER TABLE Payments ADD COLUMN BatchDate DATE;
UPDATE Payments SET BatchDate = TRY_CONVERT(Date, date_batch, 103);
Now go look at your table and sanity check it:
SELECT * FROM payments WHERE batchdate is null and date_batch is not null
This shows any dates that didn't convert. Correct their wonky bad data and run the update again.
Do another select, of all the data, and eyeball it; does it look sensible? Do you have any dates that have been put in as 02/03/2021 when they should have been 03/02/2021 etc
Now your table is full of nice dates, get rid of the strings;
ALTER TABLE Payments DROP COLUMN date_batch;
Maybe rename the column, but in SQLServer and c# WeCallThingsNamesLikeThis, we_dont_call_them_names_like_this
sp_rename 'Payments.BatchDate', 'date-batch', 'COLUMN';
Now you can do:
SELECT * FROM payments WHERE batchDate < GetDate()
And never again store dates in a string
Ok, so my SQL skills and Access skills are very rusty. I have a excel sheet with some data that I would like to start tracking into a database. Currently I pull the data, clean it up a bit and transpose it and have some excel magic work.
Currently there are two fields. Field1 is just a normal number field, less than 10 digits. Field 2 is converted into an excel date format from a UNIX Epoch timestamp.
My goal is to have the Max of Field1 for each day. Most of the older data only had one data point per day, while the newer data will possibly have hundreds data points.
Example Data:
Field1 being normal number
Field2 being Excel Date format
Field1
Field2
21107
44200.88
31827
44201.5
31827
44201.5
29355
44202.13
29355
44202.13
Assuming that you have your data in a table called Sheet1, you can type the following query in SQL view in MsAccess:
SELECT int(Field2) as ExcelDay, max(Field1) as MaxOfField1
FROM Sheet1
group by int(Field2)
int(Field2) removes the fraction from the time, leaving the Day you requested.
If you need to return both date & time as output then could try-
SELECT First(Field2) AS [Date], Max(Field1) AS MaxValue
FROM ExcelLinkTable
GROUP BY Format(Field2,"m/d/\e");
If you only want date to display then try-
SELECT Format(Field2,"mm/dd/yyyy") AS [Date], Max(Field1) AS MaxValue
FROM ExcelLinkTable
GROUP BY Format(Field2,"mm/dd/yyyy");
I've tried limiting data on monthly basis in spotfire and it's working fine.
Now I'm trying to do like getting the records from the current date to month start date.
For suppose if the current date is Sept 21, then i should get the records from Sept 21 to Sept-01(dynamically).
I have a property control to input the number of months.
The easiest way to do this is with Month and Year. For example, in your visualization:
Right Click > Properties > Data > Limit Data Using Expressions (Edit)
Then, use this expression:
Month([TheDate]) = Month(DateTimeNow()) and Year([TheDate]) = Year(DateTimeNow())
This will limit the data to only those rows with the current Year/Month combination in your data column. Just replace [TheDate] with whatever your date column name is.
In other places, you can wrap this in an IF statement if you'd like. It's redundant in this case, but sometimes helps with readability.
IF(Month([TheDate]) = Month(DateTimeNow()) and Year([TheDate]) = Year(DateTimeNow()),TRUE,FALSE)
#san - Adding to #scsimon answer. If you would like to precisely limit values between 1st of the current month to current date, you could add the below expression to 'Limit data using expression' section.
[Date]>=date(1&'-'&Month(DateTimeNow())&'-'&year(DateTimeNow())) and [Date]<=DateTimeNow()
I am struggling with a DAX pattern to allow me to plot an average duration value on a chart.
Here is the problem: My dataset has a field called dtOpened which is a date value describing when something started, and I want to be able to calculate the duration in days since that date.
I then want to be able to create an average duration since that date over a time period.
It is very easy to do when thinking about the value as it is now, but I want to be able to show a chart that describes what that average value would have been over various time periods on the x-axis (month/quarter/year).
The problem that I am facing is that if I create a calculated column to find the current age (NOW() - [dtOpened]), then it always uses the NOW() function - which is no use for historic time spans. Maybe I need a Measure for this, rather than a calculated column, but I cannot work out how to do it.
I have thought about using LASTDATE (rather than NOW) to work out what the last date would be in the filter context of any single month/quarter/year, but if the current month is only half way through, then it would probably need to consider today's date as the value from which to subtract the dtOpened value.
I would appreciate any help or pointers that you can give me!
It looks like you have a table (let's call it Cases) storing your cases with one record per case with fields like the following:
casename, dtOpened, OpenClosedFlag
You should create a date table with on record per day spanning your date range. The date table will have a month ending date field identifying the last day of the month (same for quarter & year). But this will be a disconnected date table. Don't create a relationship between the Date on the Date table and your case open date.
Then use iterative averagex to average the date differences.
Average Duration (days) :=
CALCULATE (
AVERAGEX ( Cases, MAX ( DateTable[Month Ending] ) - Cases[dtopened] ),
FILTER ( Cases, Cases[OpenClosedFlag] = "Open" ),
FILTER ( Cases, Cases[dtopened] <= MAX ( DateTable[Month Ending] ) )
)
Once you plot the measure against your Month you should see the average values represented correctly. You can do something similar for quarter & year.
You're a genius, Rory; Thanks.
In my example, I had a dtClosed field rather than an Opened/Closed flag, so there was one extra piece of filtering to do to test if the Case was closed at that point in time. So my measure ended up looking like this:
Average Duration:=CALCULATE(
AVERAGEX(CasesOnly, MAX(DT[LastDateM]) - CasesOnly[Owner Opened dtOnly]),
FILTER(CasesOnly, OR(ISBLANK(CasesOnly[Owner Resolution dtOnly]),
CasesOnly[Owner Resolution dtOnly] > MAX(DT[LastDateM]))),
FILTER(CasesOnly, CasesOnly[Owner Opened dtOnly] <= MAX(DT[LastDateM]))
)
And to get the chart, I plotted the DT[Date] field on the x-axis.
Thanks very much again.
I have very limited knowledge of creating SQL scripts for SQL Server. I need to create a pretty simple script that inserts downtime records to be posted for future dates within a database. We have daily maintenance so I'll need to post a notice for every individual day from mon-sat. There is a fixed time period of when it occurs midnight to 2AM. I'd like to create all the entries necessary for a year.
I also need to create a second script that posts notices about downtime for 1 day weekly (Sunday) which has a different backup time frame. The time frame of this weekly backup is midnight to 7AM. I'd like to create all the entries necessary for a year for this also.
The basic format of the database table I need to insert is noticetime, begintime, endtime, msgtext. Table name is downtime. All date fields except for the msgtxt which is a a text field.
How do I create a script that would increment the dates to valid days that meet the criteria as well and terminates when a specific day has been reached? Same for the weekly insert?
if I understood you correctly you would need something like this, see pseudo code below haven't tested it though:
declare
#l_maxdate datetime
,#l_date datetime
select #l_date = getdate(), #l_maxdate = '2014-12-31'
while #date < #l_maxdate
begin
if datepart(dw,#l_date) = 1 -- sunday
insert .... values .... using date variable
if datepart(dw,#l_date) > 1 -- moday - saturday
insert .... values .... using date variable
select #l_date = dateadd(dd, 1, #l_date)
end