How do I convert 1800 into a TIME, and then deduct 20 mins?
Moderator: General Moderators
-
simonmlewis
- DevNet Master
- Posts: 4435
- Joined: Wed Oct 08, 2008 3:39 pm
- Location: United Kingdom
- Contact:
How do I convert 1800 into a TIME, and then deduct 20 mins?
We are booking in times, and need to instruct people to arrive 20 minutes before the specified time.
While I can just say that, it would look better to say "please arrive by 1740"... but how do I convert 1800 into a time, and then deduct the 20 minutes?
While I can just say that, it would look better to say "please arrive by 1740"... but how do I convert 1800 into a time, and then deduct the 20 minutes?
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
All the best from the United Kingdom.
Re: How do I convert 1800 into a TIME, and then deduct 20 mi
DateTime::modify
Code: Select all
$date = new DateTime('2012-05-08 18:00');
$date->modify('-20 minutes');
echo $date->format('F j, Y H:i');-
simonmlewis
- DevNet Master
- Posts: 4435
- Joined: Wed Oct 08, 2008 3:39 pm
- Location: United Kingdom
- Contact:
Re: How do I convert 1800 into a TIME, and then deduct 20 mi
$date = new DateTime('$row1->entrydate $row1->entrytime');
$date->modify('-20 minutes');
echo $date->format('F j, Y H:i');
This is throwing up a load of errors.
$date->modify('-20 minutes');
echo $date->format('F j, Y H:i');
This is throwing up a load of errors.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
All the best from the United Kingdom.
Re: How do I convert 1800 into a TIME, and then deduct 20 mi
The code is fine. What errors are you getting? What version of PHP?
EDIT: Also, remove the single quotes around $row->whatever
EDIT: Also, remove the single quotes around $row->whatever
-
simonmlewis
- DevNet Master
- Posts: 4435
- Joined: Wed Oct 08, 2008 3:39 pm
- Location: United Kingdom
- Contact:
Re: How do I convert 1800 into a TIME, and then deduct 20 mi
[text]Fatal error: Uncaught exception 'Exception' with message 'DateTime::__construct() [<a href='datetime.--construct'>datetime.--construct</a>]: Failed to parse time string ($row1->entrydate $row1->entrytime) at position 0 ($): Unexpected character' in C:\xampp\phpMyAdmin\site\includes\search.inc:43 Stack trace: #0 C:\xampp\phpMyAdmin\site\includes\search.inc(43): DateTime->__construct('$row1->entrydat...') #1 C:\xampp\phpMyAdmin\site\index.php(89): include('C:\xampp\phpMyA...') #2 C:\xampp\phpMyAdmin\site\index.php(237): getPage() #3 {main} thrown in C:\xampp\phpMyAdmin\site\includes\search.inc on line 43[/text]
Seems it doesn't like me putting "$row1->entrytime" etc into the brackets.
Seems it doesn't like me putting "$row1->entrytime" etc into the brackets.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
All the best from the United Kingdom.
Re: How do I convert 1800 into a TIME, and then deduct 20 mi
Code: Select all
$date = new DateTime($row1->entrydate .' '. $row1->entrytime);-
simonmlewis
- DevNet Master
- Posts: 4435
- Joined: Wed Oct 08, 2008 3:39 pm
- Location: United Kingdom
- Contact:
Re: How do I convert 1800 into a TIME, and then deduct 20 mi
Bingo - brilliant. Tho I don't quite understand thsoe differences - tho I do see them.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
All the best from the United Kingdom.
Re: How do I convert 1800 into a TIME, and then deduct 20 mi
Wrapped in single quotes, the variables weren't parsed. You were passing the literal string '$row->entrydate $row->entrytime', which isn't a valid date, so DateTime::__construct threw an exception. You need to remove the single quotes so the variables are parsed, but also need to concatenate a space between them so they're read as a single argument.
-
simonmlewis
- DevNet Master
- Posts: 4435
- Joined: Wed Oct 08, 2008 3:39 pm
- Location: United Kingdom
- Contact:
Re: How do I convert 1800 into a TIME, and then deduct 20 mi
Ok, thank you. I also learned here how to remove the date part of what's echoed, so it's only 1740.
Ta.
Ta.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
All the best from the United Kingdom.