last day (15 days later) » 

8:27 PM
0
Q: Strange PHP date comparison error

Kevin Van RyckegemI don't get the expected results. Basically I just want to compare two dates (in unix format) and show the difference in months/days/hours/.. This is an excerpt of the code: UPDATE -- added more code $date = mktime($hour, $min, 0, $month, $day, $year); $now = time(); echo 'OKdate' . $date . '...

 
All code above is correct. Might it be that you overwrite the values for $seconds, $minutes, etc.? because here it shows what it should show: 0 year 0 month 0 day 4 hour 05 min 18 sec
 
@Jeffrey Wow.. Strangest thing ever. I guess so!! But it's really not obvious where, I'll have to take a deep look at this one; thanks for letting me know!!
 
If you provide more code we can help, otherwise just search for the variables or... better yet, use different names in the above part of the code! Than you can be sure that other parts of the code arent harmed.
 
@Jeffrey could you have a look? I renamed to variables to $minutes2, $...2 etc; but it didn't fix it. The template evaluated only contains {$timeleft}. Thanks! :) I found a clue to the problem by echoing all the $....2 variables => seconds 15 mins 32 hours 21 days 30 months 11 years -1
 
The above code is all correct. Some notes: use $now = time(); (not mktime() when you provide no parameters. Also $hours should be $hours2. Though, that is not the cause of the problem. What happens in $templates->get('postcountdown_post', 1, 0)? And note that $timeleft is a local variable and might not be accessible in $templates!
 
8:27 PM
@Jeffrey the template is evaluated into $temp, so the $timeleft is filled in into the template--this new template is returned to the system to be used. That part works great.
 
hi ?
 
hi :)
I didn't know there's a chat! wow
 
didn't know a chat existed :P
 
language?
 
8:28 PM
I did the small changes you said.. But I still don't understand it. Somehow years = -1; months = 11. Is PHP's date function working bad on this input? It's so strange.
What do you mean?
I speak Dutch/French, I'm from Belgium
 
great, lets continue in het Nederlands
ik zag je edit net iets te laat (was al bezig met het wijzigen van m'n comment)
 
haha oké :D vanwaar ben je?
 
eval('$temp = "{$timeleft}";'); runt bij mij uitstekend, en geeft de juiste return terug
NL
afijn, wat staat er in $template?
 
ja de eval werkt perfect..
$template staat
[quote=Hidden Post Countdown][b]Time before showing contents in this quote:[/b]
{$timeleft}[/quote]
 
ook dat werkt zonder problemen
kun je echo $timeleft doen ?
 
8:30 PM
amai, raar probleem
zal ik eens doen
-1 year 11 months 30 days 21 hours 07 minutes 55 seconds
hetzelfde dat er op het scherm tevoorschijn komt dus eigenlijk
 
kun je echo $date . ' ' . $now; doen ?
 
1437954000 1437942788
en
-1 year 11 months 30 days 21 hours 06 minutes 52 seconds
alsk het zo zie dan zou ik denken dat $difference negatief is, maar dat is niet het geval
 
kun je bovenaan ergens plaatsen:

date_default_timezone_set ( "Europe/Brussels" );
en ergens deze code:
echo date( 'Y-m-d H:i:s', $date ) . ' -- ' . date( 'Y-m-d H:i:s', $now );
 
met die timezone set werkt het precies ineens
maar daarnet werkte het met sommige datums en met andere niet
dus misschien mis ik nog iets
 
als in t lijkt te werken?
 
8:37 PM
het lijkt wel te werken ja
 
probeer anders die regel met Y-m-d H:i:s eens zonder timezone?
 
zal ik eens doen
raar nu zit het nog steeds in de vorige timezone
zelfs al heb ik die timezone code verwijderd
 
dat kan dan weer te maken hebben met een lopende sessie.
 
ah oké
dan heb ik dit als resultaat
2015-07-26 23:40:00 -- 2015-07-26 16:39:55
maar is nu wel in Brussels timezone
zal in privémodus proberen om te zien ofdat ik dan een andere timezone heb
 
daar kun je een tijdzone uitzoeken, ik nam aan dat brussels en Amsterdam zo ongeveer hetzelfde was :P
 
8:41 PM
haha ja
oké thx! lijkt te werken :D
was toch maar een raar probleem :p
 
hartstikke mooi!
ooh...
 
in privémodus is het trouwens ook nog ineens brussel timezone
wel raar :D
 
als je error_reporting( E_ALL ) bovenaan zet, dan kan het zijn dat je een notice krijgt als je niet een tijdzone hebt ingesteld
 
ah! dat zou het eigenlijk wel kunnen zijn :)
 
en dan had je ook gezien dat mktime() == time()
 
8:42 PM
maar ja, super bedankt he :D
 
geen probeem! heb het antwoord voor de correctheid toegevoegd :P
 
super :)
 
niet vergeten een antwoord te kiezen hahaha, ik heb nog één punt nodig tot de 500 ^^
 
hahaha zal je antwoord sowieso kiezen ;)
voila ze
 
Dan nog een prettige programmeer avond/nacht!
 
8:43 PM
thx, jij ook! :)
 

last day (15 days later) »