5
I have a field DATETIME
I take from SQL, format YYYY-mm-dd H-m-s
and I need to reset the hour and shorten a day.
I’m managing to decrease a day using date_modify($date, '-1 day');
, but how to reset the hour?
5
I have a field DATETIME
I take from SQL, format YYYY-mm-dd H-m-s
and I need to reset the hour and shorten a day.
I’m managing to decrease a day using date_modify($date, '-1 day');
, but how to reset the hour?
2
That takes care of:
<?php echo date("Y-m-d", strtotime("2014-03-27" . " - 1 days")); ?>
"2014-03-27" being its specific date.
You can put static time on your custom "reset" date: "2014-03-27 00:00:00"
Yes, but I believe he said decrease a day and not increase a day, but otherwise good answer.
I confused the signal, I’m already editing my answer for better understanding.
1
Try the following code:
$date = date_create('2000-01-20 01:00:00');
date_sub($date, date_interval_create_from_date_string('1 days'));
echo date_format($date, 'Y-m-d');
Response based on first example of documentation for DateTime::sub -- date_sub
.
0
Assuming you are using Mysql, try directly in the SQL expression:
SELECT CAST(seu_campo AS DATE) - INTERVAL 1 DAY;
0
I ended up doing so:
//Gerando um datetime $data novo para nao ter que colocar a parte do SQL
$data = new DateTime('2014-03-21 23:50:10');
$dia_anterior_hora_zerada = new DateTime();
$dia_anterior_hora_zerada = $data;
$dia_anterior_hora_zerada->setTime(00,00,00);
$dia_anterior_hora_zerada->modify('-1 day');
//$dia_anterior_hora_zerada = "2014-03-20 00:00:00"
Browser other questions tagged php datetime
You are not signed in. Login or sign up in order to post.
has 3 great answer and I don’t believe any of them served you, please if you find any good answer below mark it as right or give an upvote :) Thank you
– Silvio Andorinha
Right. I ended up doing it another way, I voted the one that helped me the most. I’ll post my solution, maybe help someone.
– MagisterMundus
Okay, thank you :)
– Silvio Andorinha
@Even Magistermundus you can accept your own answer, if it was the one that helped the most.
– woliveirajr