Hi, I have a job website with post type called 'Jobs' and it contains a custom field named 'Last date of application'. Now I want to display the difference between the 'Last date of application' and 'Today' i.e. days to expiry of the job.
I found one solution like https://toolset.com/forums/topic/display-difference-between-2-dates-fields/ but cannot utilize in my case.
Please help.
Hi, I think there is some issue with the code it's displaying some abrupt figures or maybe I couldn't utilize it properly.
I have used it in the 'Homepage' view (screenshot_2). You can see the front-end hidden link (screenshot_1). Please see the issue.
I am ready to provide you access to our site back-end. Thanks.
P.S.: Since this is a production site I am removing the code till it has been rectified.
Hi, your code works nicely. I made a simple change by adding '+1' in line no. 24 i.e.
return ((($field - $today_date)/60/60/24)+1).' days left';
to simply display 1 day addition to the difference between the dates. Hope the addition is ok.
Please do me a favor by making small changes into the code to display 'Just 1 day left' where the difference between the dates is just 1. And to display 'days left' where the difference between the dates is more than 1.
Hope you got my point.
Thank you.
Hi,
Another query related to the same issue. I have just noticed. I don't know whether it's a problem with the timezone or not. I am writing this when the local time is 00.20 hours and the date is September 14, 2019. So the difference between the dates should be literally 0 and since I have added 1 it should come to '1 days left'. But, in the fron end, it's showing '2 days left'. Please see the screenshot. There are three markings that can explain you things.
Hope I made you understand.
Thank you.
Hey, my date issue has been resolved. Thank you very much. But as I have asked you earlier to make necessary changes into the code to display 'Just 1 day left' where the difference between the dates is just 1. And to display 'days left' where the difference between the dates is more than 1. Hope you are getting my point.
It works, but see I wanted to show it like 'Just 1 day left', I mean putting the calculated figure between two strings. Hence I made certain changes to the code but it went wrong somewhere. Please help me with the code: