Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [PHP]odejmowanie godzin
codeszan
post 4.02.2018, 17:53:27
Post #1





Grupa: Zarejestrowani
Postów: 61
Pomógł: 0
Dołączył: 2.07.2017

Ostrzeżenie: (0%)
-----


Chciałbym wyznaczyć różnice pomiędzy dwiema godzinami.

  1. $tourChange_d = date("H:i", strtotime($tourChange)); //np. 17:00 - jako data
  2. $dateNow = date( "H:i", strtotime( "now" )); //obecna godzina np 18:43
  3.  
  4. echo $dateNow -$tourChange_d;


Message: A non well formed numeric value encountered

przykład:
obecna - 17:50
$tourChange_d - 18:40

Ten post edytował codeszan 4.02.2018, 17:54:12
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi (1 - 4)
trueblue
post 4.02.2018, 17:56:59
Post #2





Grupa: Zarejestrowani
Postów: 6 806
Pomógł: 1828
Dołączył: 11.03.2014

Ostrzeżenie: (0%)
-----


http://php.net/manual/pl/datetime.diff.php


--------------------
Go to the top of the page
+Quote Post
codeszan
post 4.02.2018, 18:12:33
Post #3





Grupa: Zarejestrowani
Postów: 61
Pomógł: 0
Dołączył: 2.07.2017

Ostrzeżenie: (0%)
-----


  1. echo date_diff($dateNow, $tourChange_d);


Message: date_diff() expects parameter 1 to be DateTimeInterface, string given

to zrobilem tak:

  1. $d1 = new DateTime($dateNow);
  2. $d2 = new DateTime($tourChange_d);
  3. echo date_diff($d1, $d2);


Message: Object of class DateInterval could not be converted to string

przeciez te daty tu już nie stringi?
Go to the top of the page
+Quote Post
trueblue
post 4.02.2018, 18:19:01
Post #4





Grupa: Zarejestrowani
Postów: 6 806
Pomógł: 1828
Dołączył: 11.03.2014

Ostrzeżenie: (0%)
-----


Porównaj dwa pierwsze przykłady z dokumentacji.


--------------------
Go to the top of the page
+Quote Post
codeszan
post 4.02.2018, 18:21:15
Post #5





Grupa: Zarejestrowani
Postów: 61
Pomógł: 0
Dołączył: 2.07.2017

Ostrzeżenie: (0%)
-----


  1. $firstTime=strtotime($dateNow);
  2. $lastTime=strtotime($tourChange_d);
  3. $timeDiff=$lastTime-$firstTime;
  4. echo "<br>";
  5. echo $timeDiff/60;


Wysnułem takie rozwiazanie czy jest ono tónie dobre jak to z dokumentacji ?
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Wersja Lo-Fi Aktualny czas: 14.08.2025 - 08:41