Asked  7 Months ago    Answers:  5   Viewed   21 times

In my PHP application I want to calculate the sum of two time variables. I am looking for something like this example.

$time1 = 15:20:00;
$time2 = 00:30:00;
$time = $time1+$time2;



The best way to do this is most likely to use strtotime to convert them to timestamps and then do the adding together:

$o = strtotime($time1)+strtotime($time2);

If I remember right strtotime does support this format.

Otherwise you will need to filter it out yourself.

Wednesday, March 31, 2021
answered 7 Months ago

Since you have the data items in GMT format, you will have to convert them to time stamps, using strtotime, more info here: Once you have the time stamp, you can subtract the offset (540 times 60 seconds) from it, and then convert the result to a new date string, using date, more info here:

Here is one version of the code that could to this:

$dbValue = $row['date']; 
$timestamp = strtotime($dbValue) - (540*60);
$result = date("Y-m-d H:i:s", $timestamp);
Wednesday, March 31, 2021
answered 7 Months ago

Assuming you get the time from the database in a variable $dbTime I'd do something like this:

$timeArray = explode (":", $dbTime );
$newTime = time() + ($timeArray[0]*60*60) + ($timeArray[1]*60) + $timeArray[2];
$finalTime = date('Y-m-d H:i:s',$newTime);

May not be the cleanest way but it is an option :)

Saturday, May 29, 2021
answered 5 Months ago

you can't print the result from mysqli_query, it is mysqli_resource and for dumping the error you need to change mysql_error() to mysqli_error()

$username = "bob";
$db = mysqli_connect("localhost", "username", "password", "user_data");
$sql1 = "select id from user_information where username='$username'";
$result = mysqli_query($db, $sql1) or die(mysqli_error());
while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) { 
    echo $row['id'].'<br>'; 
Saturday, May 29, 2021
answered 5 Months ago

yo need create the user "pma" in mysql or change this lines(user and password for mysql):

/* User for advanced features */
$cfg['Servers'][$i]['controluser'] = 'pma'; 
$cfg['Servers'][$i]['controlpass'] = '';

Linux: /etc/phpmyadmin/

Tuesday, July 13, 2021
answered 3 Months ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :