Jump to content

Date with more than 24hours


moisesbr

Recommended Posts

Hi

 

I am using command below to get datetime and storing it to varchar type field.

 

$datetime = $today[mday].'/'.$today[mon].'/'.$today[year].'    '.$horaReal.':'.$today[minutes].':'.$today[seconds];

 

I notice that I have error dates with more than 24 hours. e.g: 26:04.

 

 

Moises
 

Link to comment
Share on other sites

Thanks, I am new to php and a bit confuse.

 

I remember someone had advised me to insert it at varchar field, perhaps because I was not managing to insert it in a datatime field. 

As a matter of fact, isn't there a ready date_time() function in php as we have in other languages ?

Moises

 

Link to comment
Share on other sites

Look for where you are putting values greater than 24 into your $horaReal variable.

 
Barand

 

I was look at $horaReal origin and found out the error.

 

$today = getdate();

$num = (int)$today[hours];

$horaReal = $num +4;

 

The + 4 increment is to solve a time difference, but I suppose it does not treat it as expected.

 

Is there a better way to sum time to hour ?

 

Moises

Link to comment
Share on other sites

MySQL has a lot of functions dealing with dates and times.  So, if you are storing dates and/or times in MySQL, then you should really store them in the proper column types.

 Date is for storing ONLY date info.

 DateTime is for storing dates and times, keeping the data as you insert it.

 Timestamp converts the data to UTC time, then converts it back to your current timezone upon retrieval.

 

Along with all of these functions http://http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html, it makes no sense to store dates in a varchar field.

Edited by jcbones
Link to comment
Share on other sites

I tried:

 

     $datetime_in = new DateTime("now"); 

When try to insert   $datetime into datetime field of a mysql table, have error message:

Catchable fatal error: Object of class DateTime could not be converted to string in /home/monitorr/public_html/reembolso1.php on line 279

Tried to converto to;    $datetime_in->format("Y-m-d H:i:s"); , but there is no point.

Link to comment
Share on other sites

I finally managed to insert datetime in a real datetime field in table, using a different approach:
 

date_default_timezone_set('America/Sao_Paulo');
$datetime_in = date('m/d/Y h:i:s a', time());
 
However time is 2 hours less than Sao Paulo time.
 
Is there any issue regarding date_default_timezone_set fuction ?

Moises
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.