Error handling hours in mysql

1

I'm having a problem to accomplish adding time to a field in mysql. Using the

  

date_add (Arrival, interval ". $ item [6]." minute) ...

     

ADDTIME (Arrival, "$ item [6].") ...

The two in a given circumstance, return the value of '25: 00: 00 'at which should return '01: 00: 00'. Does mysql have another method for calculating time?

    
asked by anonymous 05.04.2018 / 14:00

2 answers

0

You can do this as follows:

// (23 horas e 30 minutos + 90 minutos) / (24 horas)
TIME((ADDTIME(TIME('23:30:00'), SEC_TO_TIME(90 * 60))) % (TIME('24:00:00')));

Being in your case, as you reported in the comment:

  • Arrival: 23:30:00
  • Time: 90 (minutes)

TIME((ADDTIME(TIME(Chegada), SEC_TO_TIME(Tempo * 60))) % (TIME('24:00:00')));
    
05.04.2018 / 15:17
0

You can have this time generated at the time of insertion in the mysql database.

By putting this code ("NOT NULL DEFAULT CURRENT_TIMESTAMP" timestamp) in front of a DATABASE (EXAMPLE) column, so when you insert it it automatically picks up the date and time it is entered into the database

    
05.04.2018 / 14:02