sadboys Posted October 20, 2017 Share Posted October 20, 2017 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 Also in the view after the ticket is created it shows like this Quote Link to comment Share on other sites More sharing options...
ginerjm Posted October 20, 2017 Share Posted October 20, 2017 Perhaps if you read the MANUAL you would find the proper formatting string for the date() function. Here's a link. You should get familiar with the MANUAL. http://php.net/manual/en/function.date.php Quote Link to comment Share on other sites More sharing options...
sadboys Posted October 20, 2017 Author Share Posted October 20, 2017 Perhaps if you read the MANUAL you would find the proper formatting string for the date() function. Here's a link. You should get familiar with the MANUAL. http://php.net/manual/en/function.date.php Isn't this the proper format for timestamp - YYYY-MM-DD HH:MI:SS ? Quote Link to comment Share on other sites More sharing options...
Sepodati Posted October 20, 2017 Share Posted October 20, 2017 Did you click the link and still not get an answer? It lists out VERY CLEARLY what the format should be for date()... Quote Link to comment Share on other sites More sharing options...
sadboys Posted October 20, 2017 Author Share Posted October 20, 2017 (edited) 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" Edited October 20, 2017 by sadboys Quote Link to comment Share on other sites More sharing options...
Sepodati Posted October 20, 2017 Share Posted October 20, 2017 Does that work for you, then? Quote Link to comment Share on other sites More sharing options...
Barand Posted October 20, 2017 Share Posted October 20, 2017 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. Quote Link to comment Share on other sites More sharing options...
sadboys Posted October 20, 2017 Author Share Posted October 20, 2017 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 Quote Link to comment Share on other sites More sharing options...
Barand Posted October 20, 2017 Share Posted October 20, 2017 Mysql timestamp format is not the most friendly format to display to users. Something like "jS F Y g:ia" might be better for mere humans. Quote Link to comment Share on other sites More sharing options...
kicken Posted October 21, 2017 Share Posted October 21, 2017 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. Quote Link to comment Share on other sites More sharing options...
cloetensbrecht Posted October 22, 2017 Share Posted October 22, 2017 You probably need Y-m-d H:i:s Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.