Jump to content

Date and Time does not show proper result


sadboys

Recommended Posts

Hello, I need a little help here. I'm using Yii2 Framework

 

In my TicketController, I have a function that if you create a ticket it will automatically get the system time.

 

In time_start I used TIMESTAMP

 

TicketController.php

 

actionCreate

$model->time_start = date('YYYY-MM-DD HH:MI:SS');

In the form it does not show the proper result

 

0PXOSrxSToCgbablqB-A0A.png

 

Also in the view after the ticket is created it shows like this

 

ajbEFjTGQ3W_HidCgBbopw.png

Link to comment
Share on other sites

Did you click the link and still not get an answer? It lists out VERY CLEARLY what the format should be for date()...

 

I've already read that before but I thought I can also use the format of timestamp in mysql, I'm currently using "y-m-d h:i:s"

Link to comment
Share on other sites

You can get mysql to insert the current datetime automatically without resorting to PHP and inserting the value in your query. Specify a default value of "CURRENT_TIMESTAMP" for your timestamp column. Alternatively, you can insert a value of NOW() with your query.

 

Yeah, in my db the default value is already "CURRENT_TIMESTAMP", but I want the time to be displayed on the form so what I did was like that. Thank you anyways

Link to comment
Share on other sites

Isn't this the proper format for timestamp - YYYY-MM-DD HH:MI:SS ?

Each letter in the string you give to date stands for something specific. For example Y means A full numeric representation of a year, 4 digits, so when you tell date to use the format YYYY, you're telling it you want "(the four digit year) x 4", hence you get 2017201720172017

 

Humans/other software may understand that 'YYYY' means a single 4-digit year (as opposed to 'YY' being a 2-digit year) but that's not how PHP was designed so you need to forget that style and use PHP's style.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.