Subtract a day directly from CURRENT_DATE

Asked

Viewed 312 times

0

I am using a framework that allows me to set the current date as default value, but now I need to show the user always the date yesterday, the code snippet as the value set is this:

$editor = new DateTimeEdit('datacadastro_edit', false, 'd-m-Y');
$editColumn = new CustomEditColumn('Data Cadastro', 'DataCadastro', $editor, $this->dataset);
$editColumn->SetReadOnly(true);
$editColumn->SetAllowSetToNull(true);
$editColumn->SetInsertDefaultValue($this->RenderText('%CURRENT_DATE%'));
$this->ApplyCommonColumnEditProperties($editColumn);
$grid->AddInsertColumn($editColumn);

What I tried to do was this:

$editColumn->SetInsertDefaultValue($this->RenderText('%CURRENT_DATE%'.' - 1 days'));

But the date displayed is today’s, I don’t know exactly if this is the right way to do it.

2 answers

2

This is not looking like a native class or some strongly known lib, however how did you use the mysql tag if a column in a SELECT:

SELECT CURRENT_DATE - INTERVAL 1 DAY

If to return only the results of "yesterday":

SELECT colunas FROM tabela WHERE DATE(coluna_de_data) = DATE(CURRENT_DATE - INTERVAL 1 DAY);

In the INSERT:

INSERT INTO tabela (coluna1, coluna2, colunadedata)
VALUES ('valor1', 'valor2', CURRENT_DATE - INTERVAL 1 DAY)

In the UPDATE:

UPDATE tabela
SET coluna1='valor1', column2='valor2', colunadedata=CURRENT_DATE - INTERVAL 1 DAY
WHERE <condição para edição(ões)>

1


In MYSQL all these work well :

SELECT
 CAST(current_date()-1 as date),
 Date(current_date()-1),
 DATE(CURRENT_DATE - INTERVAL 1 DAY)

inserir a descrição da imagem aqui

Browser other questions tagged

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