I have two dates given as Zend_Date(). I must check the following:
if theese dates are in the same month day (for example: second day of the month, year does not matter),
if dates are from exactly the same day(for example 2 december 2012);
To check the dates are the exact same day, you can check each individual part separately.
Zend_Date('your-date-here',Zend_Date::DAY);
This returns a date object that specifically gives you the day for the 'your-date-here' and it accepts a variety of formats; for example, I use php's date function as:
$myDate = date('Y-m-d-H-i-s');
$dateDayObject = Zend_Date($myDate, Zend_Date::DAY);
and now $dateDayObject will have the value of the 'd' in it.
You can use DAY, WEEK, YEAR... there are many constant all defined here:
http://framework.zend.com/manual/1.12/en/zend.date.constants.html
Finally, to test if they are in the same day of the month, you can use a combination of loops and if statement and the same method as above to write your own function to check the day within the month or there may be a defined constant for it. Good luck.
Related
The method should retrieve the date in the previous week that corresponds most closely to the specified date.
fromdate = prevMth(systemDateGet());
need to change the above code so that i could get the date of the previous week instead of previous month with respect to the present date.
No function is needed, just use date arithmetic.
systemDateGet() - 7
This will return the prior week date. This of cause implies you use a calendar with 7 day weeks.
Some additional things you may find useful:
wkOfYr(...)
dayOfWk(...)
DateTimeUtil::[VariousFunctionsHere]
In D365FinOps you can also use:
HcmDateTimeUtil::calculateDateWithOffset(PeriodUnit::Day,7,false)
]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
I am trying to compare yesterday's data to the same day the year before. For example, yesterday is 11 November 2018. I want to compare to 12 November 2017 (same day but the year before). I am wanting this to be applied automatically on the filter so all I need to do is open the file and verify the numbers are correct before sending off the report.
Any help would be appreciated.
Thanks
There are many Tableau functions that manipulate dates. A couple in particular are relevant to your problem:
Today() - returns the current date
DateAdd() - adds or subtracts an interval from a date. For instance, DateAdd('year', Today(), -1) gives the date one year prior to today. The first argument to DateAdd is the level of granularity or date part.
DateDiff() - determines the difference of the interval between two dates. DateDiff('day', [Start Date], [End Date]) returns the number of days separating the two date arguments.
The functions are well documented in the online help. Construct the formulas you need and filter accordingly.
Isolate yesterday's date as its own field. For instance if that is the max date in your data, then {max([Date])} would create an LOD of the maximum date.
Then make a calculation that will display the same date last year:
year([Date]) = year([max_date])-1
and datepart('week',[Date]) = datepart('week',[max_date])
and datepart('weekday',[Date]) = datepart('weekday',[max_date])
How can I convert the month and year of a date to match a variable named by a month indexing system used in a study where January 1986 is month 1? I need to create a variable that calculates the difference between the current month and Jan 1986 but am not sure how to get started. My dates are currently in YYYYMMDD format.
The intck function tells you how many intervals of something occur between two dates.
monthnum = intck('month','01JAN1986'd, surveydate);
If you only have month/year, you can use the mdy function to construct a date.
dtvar = mdy(monthvar,1,yearvar);
I am developing a plugin written in Lua, and I need a way to calculate Unix time or at least a way to compare 2 date strings.
The function I can use only returns date string in the following format
"1/17/2014 6:50 PM"
Is there a way to convert this string to a Unix time?
Unfortunately I don't have access to the OS library so things like os.time() do not work.
Is there any library or something similar that I can work with?
I also thought about splitting the string into parts, but I need a way to add/subtract time
Just compare normalized timestamps:
function normalize(a)
local m,d,y,h,mi,n=a:match("(%d+)/(%d+)/(%d+)%s+(%d+):(%d+)%s+(%w+)")
if n=="PM" then h=h+12 end
return string.format("%04d%02d%02d%02d%02d",y,m,d,h,mi)
end
Date arithmetic is another story. For a complete, pure Lua date library, see luatz or https://github.com/Tieske/date.
If you need to only compare two time, you don't need to get each time's Unix timestamp. One possible solution is to get the time fields from the string like this:
local time = "1/17/2014 6:50 PM"
local month, day, year, hour, minute, am_pm = time:match("(%d+)/(%d+)/(%d+)%s+(%d+):(%d+)%s+(%w+)")
print(month, day, year, hour, minute, am_pm)
Output: 1 17 2014 6 50 PM
Then compare two time from comparing their year, if they are equal, then month, and so on. Remember to use tonumber to compare them by number, not the string itself.