Error handling hours in mysql

Asked

Viewed 40 times

1

I’m having a problem adding time to a field in mysql. When using the function

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

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

Both in a given circumstance, return the value of '25:00:00' in which it should return '01:00:00'. mysql has another method for calculating time ?

  • What is the value you are receiving in Arrival and what value is passing from $item[6]?

  • UPDATE trip SET Exit = ADDTIME(Arrival, '01:30:00') Where id = 4518 Arrival 23:30:00 Exit 25:00:00 Time 90

2 answers

0


You can do it this way:

// (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
  • Weather: 90 (minutes)

TIME((ADDTIME(TIME(Chegada), SEC_TO_TIME(Tempo * 60))) % (TIME('24:00:00')));

  • It worked out Valeu Vinícius !

  • @Welliton I’m glad I helped! Please don’t add "thank you" to the comments. Instead, vote for the answers you find useful. : D

0

You can cause this time to be generated, at the time of the Insert, in the mysql database.

putting this code ("timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP") in front of a DATECASTRO column (EXAMPLE), so when you enter it automatically picks up the date and hhora that is inserted in the database

  • He has an hour for departure and a time in time in minutes to arrival, with this I need to convert this minute in hours to add in the arrival field.

  • A yes, so I won’t be able to help you, I’m sorry I just misunderstood what you wanted!!

  • No problem, thank you very much !

Browser other questions tagged

You are not signed in. Login or sign up in order to post.