difference between dates and times

gapper

Member
Some months ago, I saw a code in the wiki to calculate the difference between 2 dates and maybe there was also a code for the difference between 2 times. Now I cannot find both of them in the wiki. Please if it is still available in the wiki could you post the link?
 
Did you try doing this?

http://screencast.com/t/oGtfXPTYIh

... and any other combinations of keywords that might work, like time, diff, etc. All I can do is search using the same page you use to search, as I don't know what people may have added / removed from the wiki, and it wasn't something I personally added.

Are you wanting Javascript or PHP?

-- hugh
 
I didn't know that method to search in wiki. Thanks for the video.
Between php or javascript please choose the easiest. Thanks
 
I can't decide that for you, as I have no clue what you are trying to do.

PHP runs on the server, you'd use it in things like setting element defaults, validations, form submission scripts, etc.

JavaScript runs in the browser, you'd use it in custom element JS code, custom form_X.js scripts, etc.

-- hugh
 
Thanks for the clarification.
It will be an element into a form which should return automatically the difference between two dates selected into the same form.
Therefore it should be JavaScript.
 
could you define 'difference' ? do you want to show the number of days between the two dates?
 
yes, it is correct, thanks.
The days number between dates in case of date or the hours number between times in case of time.
 
Thanks for the clarification.
It will be an element into a form which should return automatically the difference between two dates selected into the same form.
Therefore it should be JavaScript.


Doesn't necessarily mean it should be JavaScript. You'd only need to do it in JS if you want to display the result to the user, and do it in 'real time' so when you change one of the two dates, the difference gets immediately calculated.

if you just want to store the difference once the form is submitted, it'd be easier to do it in PHP, using either a form submit plugin, or a calc element.

So ... do you need to show the difference to the user in 'real time' on the page, or just calculate it when the form is submitted, for storing in the table?

-- hugh
 
I would like the javascript because it would be nice to let the user see it in real time with no chance to modify it (it just depends on only the dates or times selected).
If it is easier to write it in PHP, then it could be ok the submit plugin or the calc element. The PHP fulfill the essential too.
 
I have used it, but the number I see in the list is something like: 15927- 15950 -15947 - etc. for the other records.
If the days (the difference between two dates) are 2, I would like to see 2 in the list. How can I do?
 
I am attaching a snapshot about the code I pasted in the calc field
 

Attachments

  • calc for dates.jpg
    calc for dates.jpg
    47.1 KB · Views: 316
$nowdate = strtotime("{table___element}");
$thendate = strtotime("today");
$datediff = ($thendate - $nowdate);
$diff = round($datediff / 86400);
return $diff;
so
no PHP: in 1st line
{} missing in 3rd line ("today" is a keyword, no element placeholder)
 
I have tried the attached code to know the difference between times.
I filled the frontend with an example for a difference of 4 hours. The result is about 383,000.
I would want to know the hours number.
Is the code correct?
 

Attachments

  • calc for difference between times.jpg
    calc for difference between times.jpg
    39 KB · Views: 326
When posting code, can you just copy and paste the code, using the code button in this editor (the {} button), rather than uploading a screenshot of it? It is very hard to read code in screenshots, and makes it impossible for us to copy and paste it, either for testing, or to paste it back to you, with corrections.

At a first glance, one obvious issue is the double {{braces}} around the second date placeholder. Not sure if that's the only issue, but remove the extra pair and try again.

-- hugh
 
Also, with dates, it is often better to use the _raw placeholder (just append _raw to the placeholder name), as that should always be the standard MySQL representation, whereas the non _raw placeholder could be a different format (depending on exactly where / when your code is running).

-- hugh
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top