Getting last day of the current month - date

I can get the last day in php using cal_days_in_month(CAL_GREGORIAN, 03, 2014); function and then assign it to view. But I want to know is it possible to get the last day in current month using smarty date_format function?
Thanks in advance

I'm not sure you can solve this only using the date_format function. I wouldn't do it anyway, since this put way too much application logic into the template.
But... if you want to do this anyway, just add a template function to get what you want.
PHP:
$tpl = new Smarty();
$tpl->registerPlugin("function","lastdayofmonth", "smarty_function_lastdayofmonth");
$tpl->display('your_template.tpl');
function smarty_function_lastdayofmonth($params, Smarty_Internal_Template $template) {
return date("Y-m-t", strtotime($params['date']));
}
Smarty:
{assign var='datevar' value='2014-03-06'}
{lastdayofmonth date=$datevar}
Output:
2014-03-31
Keep in mind, this is just an easy example. There are more than one way to use plugins within Smarty.

Related

I'm new to ionic, can anyone help me . I'm using ionic 1 .

I'm new to ionic , I want to record the last date when the app is refreshed by an user and need to show the same value in UI. The value should come as one hour back, 2 hours back and so forth ....if the app is refreshed yesterday then it should say yesterday. Even if u tell me a function then i will be good to go. Thank You.
You could use moment.js, which provides you with functions for obtaining the current timestamp - moment.now() - and to parse it into human-readable strings - moment('1496239022').fromNow().
You can even choose the locale so the human-readable strings are properly translated - moment.locale()
In essence, you would save the refresh time using moment.now() (how or where you save it is up to you - you can use localStorage if you want) and then use moment.js to show the time.
thnx alot for this solution, I solved the problem using a different method. I created variables to store current time and saved it in an array . And compared them to print time difference where in time-diff function has if-else condition to print it to be minute hour and so on. ! :) I will try ur solution now.And will let u know if it works !.Thanx again !

How to get the current year from freemarker template

I have use the ${.now} to get the current time stamp inside the freemarker templates, but I want to know how can I get only the year?
Like ${.now?string('yyyy')}. (Note that this will return a string, which is what you want if you only want to print it. If by any chance you need a number, so that you can do arithmetic with it, then it's .now?string('yyyy')?number.)

regarding calculating business days/holidays

does anyone know where I can download this zip file called "businessdays.zip" which was mentioned from this link ... http://www.tek-tips.com/viewthread.cfm?qid=136159 ... I mean is there a better way of calculating business days/holidays than what is previously written here ... http://www.experts-exchange.com/Database/Reporting_/Crystal_Reports/Q_21376129.html ... I've tried this but method from experts-exchange, registered the dll but still not working for me. Can anyone help?
You could create a custom function that returns an array of holidays. See my answer to Crystal Report exclude time entries based on holiday rules.
In this post there is a function that takes a start date, and end date and return the number of working days in between. Also takes holidays into account.

How to make Jasper Reports programmatically determine the Name of Columns within the report it self?

I am generating a report with that will have a 7 columns where the last 6 should have the the last 6 months listed. So as of the time of this writing it should be:
NAME -> September -> August -> July -> June -> May -> April
ss the column headers. I am trying to avoid having to pass them in as parameters, and am trying to get Jasper Reports to figure it out at runtime. I can get the first month pretty easily using a Text Field Expression. It looks like:
new java.text.SimpleDateFormat("MMMMM").format(new Date())
The issue comes in with the other months. I initially tried
new java.text.SimpleDateFormat("MMMMM").format(java.util.Calendar.getInstance().add(Calendar.MONTH, new Integer("-1)).getTime())
This does not work since Calendar.add does not return a Calendar instance. I then tried using a variable and then a combination of variables which also did not work.
How to make Jasper Reports programmatically determine the Name of Columns within the report it self?
I think the best approach to solving this problem is to use Commons Lang. That package provides utilities to make calculations like this very easy. By adding one extra jar you can then use expressions like this:
DateUtils.addMonths(new Date(),-1)
I find that easier to maintain than first creating a helper Calendar class and then using the ternary operator but ignoring its results.
$P{cal}.add(Calendar.MONTH, -1)
? null : $P{cal}.getTime()
If you ever need to generalize the solution then it's a lot easier to get a Date back from a SQL query than to get a Calendar. So you can quickly change to "DateUtils.addMonths($F{MyDate},-1)". Initializing a Calendar to match a date returned by a query isn't nearly as simple. But of course there's a certain benefit to not having to add one more .jar file. So sometimes that ternary operator technique is the quickest way to get things done.
I wrote about using the Commons Lang approach a couple of years ago here: http://mdahlman.wordpress.com/2009/09/09/jasperreports-first-dates/
I also needed a certain format for the previous month. I ended up combining the other two answers:
new java.text.SimpleDateFormat("yyyyMM").format(
org.apache.commons.lang3.time.DateUtils.addMonths(
new java.util.Date(),
-6
)
)
This way I don't need to add another parameter. Adding the Commons Lang jar is a non issue for me since JasperServer 5.5 comes with version 3.0 out of the box.
I hope this helps someone who stumples upon this page, just like I did.
I found a working solution that is pretty ingenious (no I did not come up with it). I found it here. The gist of it is create a parameter called call, with a default value of:
Calendar.getInstance()
and un-check the option 'Use as a prompt'. Then in your text field expression you would do:
new java.text.SimpleDateFormat("MMMMM").format(
(
$P{cal}.add(Calendar.MONTH, -1)
? null : $P{cal}.getTime()
)
)
What happens is it will set the default value for the calendar instance, then execute the add method, which will resolve to false, so then it will then return the result from getTime() method which gets formatted how I want.

Classic Asp Date

Hey, been looking for a while but I can't seem to find any info on how to handle date in classic asp.
For now, I need a way to calculate the number of days passed in the current year. I was thinking about a simple function that would take the current date, then make another date with (day = 1, month = 1, year(now)). And finally get the datediff(day) for these two. Easy enough, but I can't figure out how to do this. Help is appreciated!
Perhaps this example can help you? https://web.archive.org/web/20211020135923/https://www.4guysfromrolla.com/webtech/110398-1.shtml
DateDiff("d",DateSerial(Year(Now),1,1),Date)