i want to make stackoverflow timestamps(X minutes ago, etc). How i can make it using zend_date? I found How to calculate time passed with PHP or Zend_Date? this realisation, but it uses other library. Are there any different ways?
How about Zend_Date::subDate()?
$d1 = new Zend_Date();
$d2 = new Zend_Date($old_date);
$diff = $d1->subDate($d2);
After you've got the difference, you can check out one of these helpers:
Relative time view helper
Zend_View_Helper_Relativetime
Even if you don't want the whole Zym framework, you could still add their TimeSince view helper to your own application.
You can subtract timestamps of two dates to find difference between them in seconds and then use division and modulo to represent it as minutes, days etc.
Related
First of all, I'm new to SPSS modeler, sorry if my question sound too obvious for experts, but what I'm trying is to calculate the date difference between two date values ( arrive_Date , Depart_Date ) in (Hours), I used this function time_hours_difference , this function works okay if the Arrive_Date and depart_date are the same day, but if the days are different, the date difference is in negative value, I searched and enabled this option: Rollover days/mins in stream properties, but the problem remains the same.
I hope you can help me with this beginner question.
Thanks
Hope its not too late. You are getting negative values because time_hours_difference extract only the time from the two specified timestamps and computes the difference out of it. It doesn't take the date values into account.
For example:
time_hours_difference('2012-08-02 14:10:50,2012-08-05 13:36:26)
Output:
-0.573
Remember, here time_in_hours('0130') under time format 'HHMM' evaluates to 1.5.
Here is my solution: in order to take days into account, first extract date_days_difference and multiply it with 24 to bring it in Hours and then sum it up with the time difference using time_hours_difference.
date_days_difference(arrive_Date,Depart_Date)*24 +
time_hours_difference(arrive_Date,(to_string(datetime_date(arrive_Date)) >< " 23:59:00")) +
time_hours_difference((to_string(datetime_date(Depart_Date)) >< " 00:00:00"),Depart_Date)
Im having a problem with a datepicker on vb6, but this jus happen on certain dates, for example 31/01/2017, but with another dates it works fine.
I appreciate the help
This almost certainly has to do with how you are setting the date in the control.
For instance if the control's value is ANY month that does not have 31 days then you will get that error. Trying to set the control to 31/02/2017 would cause an error 380.
There are two approaches you can take to fix this.
Reverse the order you set the date components.
dtFecha.Year = Year(fcsAux.Fields("xf3ch4"))
dtFecha.Month = Month(fcsAux.Fields("xf3ch4"))
dtFecha.Day = Day(fcsAux.Fields("xf3ch4"))
Set the Value property instead of the date components. dtFecha.Value = "31/02/2017"
dtFecha.Value = rcsAux.Fields("xf3ch4").Value
The first approach ensures the month is always appropriate for the day. The second approach sets the entire value at one shot and should be a valid date.
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 !
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.
i am building a small application to calculate employee attendance.
A user will check in, his check in time will be recorded in a mysql datetime format, for example
check_in_time 2011-12-16 20:27:20
And when he checks out
check_out_time 2011-12-16 20:27:27
I can do it the conventional way by exploding and doing the subtraction, but am sure Zend_Date has a more efficient way of doing it.
Obviously my question was not hard to answer, anyhow this is the answer to get the time diff in seconds, then i can handle seconds normally.
Thanks for the docs #ajreal, i did not look correctly into them.
public function getTimeInSeconds($dateStart, $dateEnd) {
$dateStart = new Zend_Date($dateStart);
$dateEnd = new Zend_Date($dateEnd);
$new = $dateStart->sub($dateEnd);
$timeInSeconds = $new->getTimestamp();
return $timeInSeconds;
}