Calendar quarter-end immediately preceeding any given date - date

Essentially I may have any date and I want to get the proper quarter-end date for the previous quarter.
Three examples:
19/07/2013 -> 30/06/2013
30/06/2013 -> 31/03/2013
28/02/2013 -> 31/12/2012
In Excel VBA it seems using DateAdd to subtract a quarter just subtracts three months from the date, e.g. 19/07/2013 -> 19/04/2013. This is no good for me.
What do you think would be the best way of doing this?
Perhaps extracting the month part and then comparing it to a list of the
possible quarters?
Or maybe having some sort of null date
01/01/2000 and then adding the number of quarters the given date
shows as to this null date and then subtracting a day to get a
previous quarter-end position (although this might cause problems
when the date flips under a year to December 31)?

Please consider:
=IF(MOD(MONTH(A1),3)=0,EOMONTH(A1,-3),
IF(MOD(MONTH(A1),3)=1,EOMONTH(A1,-1),
EOMONTH(A1,-2)))
Edit: There is a better answer in the comments.

Related

How do we calculate difference and percent difference between two columns in tableau

]Difference and percent Difference must be calculated.
I cannot do Apr20-MAy20 because it is not always the same. I need to show the current month and previous month
So I did a relative filter to just show the current month and previous month.
So the difference of two columns should automatically change when the month changes.
Now how do I get the same month of prior year, how do I filter ?
I also need to calculate the difference of current year same month and previous year same month.
Thank you in advance for any help!
When I do table across difference, the difference value is overwriting the existing May and Apr month values as the below screen shot, how to show the difference in another column
Currently:
Below is Expected:
Sounds like you should create a custom filter for the dates. You want:
This month this year
This month last year
Last month this year
There are a number of ways you could do this. I'll give one example and will assume there aren't any future dates in your data set.
[DateFilter]: DATETRUNC('month',[YourDateField])>=DATETRUNC('month',DATEADD('month',-1,TODAY())) OR DATETRUNC('month',[YourDateField])=DATETRUNC('month',DATEADD('year',-1,TODAY()))
Put the to the filters shelf, set to True, and it should keep the months you want.
Then you can just use the standard table calculations to calculate Difference and Percent Difference.
Note, the formula isn't tested, just typed directly into here, let me know if it doesn't work
Based on your comments look at creating separate calculations for to YoY / MoM / etc calculation. That also means creating calculated fields to isolate the Current Month, Previous Month, etc.
For example, the current month:
[isCM]: DATETRUNC('month',[YourDateField]) = DATETRUNC('month',TODAY())
The previous month:
[isPM]: DATETRUNC('month',[YourDateField]) = DATETRUNC('month',DATEADD('month',-1,TODAY()))
Then month on month, something like:
[MoM]: (SUM([Measure])*INT([isCM]))/(SUM([Measure])*INT([isPM]))
To make your table check this article about using the placeholder technique to create tables in Tableau

How can I make a database structure in mongodb for saving the date range?

Here I'm saving the date range using golang. Suppose we have to save the all monday comes between the range of the 1-may-2018 to 14-july-2018.
How we will find all the monday between these range using golang and on the other hand we have set the start_time (8:00 A.M.) and the end_time (6:00 P.M.) of the first two coming monday in the database but on the third monday we have a change in the schedule that there is a time change like start_time (9:00 A.M.) and end_time (5:00 P.M.). Then how I will make my database to make this situation in practically using the golang.
Can Anybody help me for this to solve this solution. I made a database for and I do ppr work on it and make some fields shown below:-
Fields for Schedule //Schedule is a collection name
Id (int)
Day (string)
Start_hours (int)
Start_minutes (int)
End_hours (int)
End_minutes (int)
Start_date (timestamp)
End_date (timestamp)
How I will select monday between the selected range and how will I do the situation I explained above can anybody give guidance to me to make this situation easier. Thank you if this is a basic question then I'm really sorry.
I'd make something like this.
Find the first Monday date from the date range (see for example How do I get the first Monday of a given month in Go?
Mondays happen every week, so you can easily find the rest of dates by adding 7 days till the end date
Store all the Monday dates you found with the start and end times
I wouldn't bother with hours and minutes as you can easily get them from the timestamps in Go. Here is the simplified DB structure I would make
Fields for Schedule //Schedule is a collection name
Id (int)
Day (string)
Date (timestamp) // the actual date
Start (timestamp)
End (timestamp)
You don't need any more fields. You can get the day of the week (Day (string) in your structure, e.g. Monday) from the Date field too, but I believe if you want to query the collection by different days, this might speed things up, but be careful if you need to adjust for time zones. If you work with more than one, then store everything in UTC and you may have an extra filed Timezone, cos a date could be Monday for one zone and Sunday for another.
So, the Schedule will hold weekdays and start and end times for each of them. I'm not sure if you need to store initial date ranges, the Schedule collection will hold that range as well, form the first record to the last one. In my mind, I'd initially populate the collection with a given date range, then later on, I can modify it by adding new days, or deleting them.
When you query this collection with some start and end date range for the Date field, if your first result comes newer than 7 days from the start, this means you miss 1 or more entries from the start. If the last result comes older than 7 days from the range end, this means you miss some entries prior to the range end.
There is nothing specific to Go, in my opinion, Go works well with dates and you don't need any special date structures in your DB.

800xA, assigning and manipulating dates

I have a quick question regarding handling of dates and times in 800xA.
What I´m trying to do is to take the current date, add/subtract days and save the result to a new variable.
I´m currently using "Date_and_timetocalendarstruct", to split the current date down to "current year", "current month", "current week" and so on.
I want to work it like this :
for example : take the current date and subtract it by one (or any other number) and thus, generating a new date to store away for future use.
This particular scenario is in ABB,s 800xA systems and its configured against a AC 800M controller.
I have tried a couple of things so for, regarding applying arithmetic operations to dates, but without success.
I hope someone here could point me in the right direction.
Thanks in advance
I think what you missed is the time data type.
date_and_time is used for a Calendar type of Data while time is a time span, e.g. a number of days.
What I understand you want to calculate is (in ST, but works in FBD as well):
OutDate := sub( InDate, Days);
Where OutDate and InDate are of Type date_and_time and Days is time.
If you specify Days with Value 5d, you will get OutDate as 5 days before InDate.
In a similar way, you will get a time span (type time) as output when subtracting two date_and_time values!

Number of days between past date and current date in Google spreadsheet

I want to calculate the number of days passed between past date and a current date. My past date is in the format dd/mm/yyyy format. I have used below mentioned formulas but giving the proper output.
=DAYS360(A2,TODAY())
=MINUS(D2,TODAY())
In the above formula A2 = 4/12/2012 (dd/mm/yyyy) and I am not sure whether TODAY returns in dd/mm/yyyy format or not. I have tried using 123 button on the tool bar, but no luck.
The following seemed to work well for me:
=DATEDIF(B2, Today(), "D")
DAYS360 does not calculate what you want, i.e. the number of days passed between the two dates – see the end of this post for details.
MINUS() should work fine, just not how you tried but the other way round:
=MINUS(TODAY(),D2)
You may also use simple subtraction (-):
=TODAY()-D2
I made an updated copy of #DrCord’s sample spreadsheet to illustrate this.
Are you SURE you want DAYS360? That is a specialized function used in the
financial sector to simplify calculations for bonds. It assumes a 360 day
year, with 12 months of 30 days each. If you really want actual days, you'll
lose 6 days each year.
[source]
Since this is the top Google answer for this, and it was way easier than I expected, here is the simple answer. Just subtract date1 from date2.
If this is your spreadsheet dates
A B
1 10/11/2017 12/1/2017
=(B1)-(A1)
results in 51, which is the number of days between a past date and a current date in Google spreadsheet
As long as it is a date format Google Sheets recognizes, you can directly subtract them and it will be correct.
To do it for a current date, just use the =TODAY() function.
=TODAY()-A1
While today works great, you can't use a date directly in the formula, you should referencing a cell that contains a date.
=(12/1/2017)-(10/1/2017) results in 0.0009915716411, not 61.
I used your idea, and found the difference and then just divided by 365 days. Worked a treat.
=MINUS(F2,TODAY())/365
Then I shifted my cell properties to not display decimals.
If you are using the two formulas at the same time, it will not work...
Here is a simple spreadsheet with it working:
https://docs.google.com/spreadsheet/ccc?key=0AiOy0YDBXjt4dDJSQWg1Qlp6TEw5SzNqZENGOWgwbGc
If you are still getting problems I would need to know what type of erroneous result you are getting.
Today() returns a numeric integer value: Returns the current computer system date. The value is updated when your document recalculates. TODAY is a function without arguments.
The following worked for me. Kindly note that TODAY() must NOT be the first argument in the function otherwise it will not work.
=DATEDIF( W2, TODAY(), "d")
Today() does return value in DATE format.
Select your "Days left field" and paste this formula in the field
=DAYS360(today(),C2)
Go to Format > Number > More formats >Custom number format and select the number with no decimal numbers.
I tested, it works, at least in new version of Sheets, March 2015.

Set one date from another date

I am using Objective-C within X-code.
I am iterating through a dictionary which contains a date value as one of it's keys. All I want to do is get an array of all the distinct dates so I can use them in a table, as headers. I just plan on
iterating the dictionary and adding dates to a mutable array each time I encounter a new date.
I must set previous date to new date for comparisons to work and I am having a very difficult time figuring out how to set one date equal to another date.
This seems like it should be such a simple thing to do and I am trying to avoid converting the dates to strings first - but if that's what I have to do, then so be it.
Any help would be appreciated.
Thanks,
Gerry O.
If you know the time offset is same as GMT, you could do it by dividing the date's timestamp by 86400 seconds (or three more 0s in milliseconds) and comparing those. If a time offset is there, add or subtract by 3600 seconds per hour before you divide them. But then again, leap years and seconds would break that...
Most languages have libraries support extracting the year, date, month, etc. They take everything into account, usually.
In Objc, you can get a NSDateComponents from NSCalendar's components:fromDate: method. After this, you can call the components to see exactly what each component (I suggest year, month, day) is.
I think you want code to compare dates and You need two loops nested.... where in outer loops iterates with conditional inner loop... In inner loop you just check that previously you had the same date or not...
please go through the below post on same site...
How to compare two dates in Objective-C
hope you will get solution... else clarify your question....