cakePHP incorrect datetime format - mysql

I am new to cakePHP.
Currently I am facing this trouble, it show me this error when I login to cakePHP project.
**Database Error**
Error: SQLSTATE[22007]: Invalid datetime format: 1292 Incorrect datetime value: '2015-10-22T15:42:20+08:00' for column 'last_login' at row 1
SQL Query: UPDATE `cakephpdb`.`users` SET `last_login` = '2015-10-22T15:42:20+08:00', `modified` = '2015-10-22 15:42:20' WHERE `cakephpdb`.`users`.`id` = '37'
I think this can be configure in cakePHP config file (which just edit in 1 file that can affect the entire project) or maybe change the MySQL setting.
Below is detail:
CakePHP project: Hosted and run in IIS server
MySQL: in another server
MySQL version: 5.5.38
Many thanks for help! Thank you.

Invalid datetime format: 1292 Incorrect datetime value: '2015-10-22T15:42:20+08:00'
Pass the correct datetime format: YYY-MM-DD HH:MM:SS This is what I would assume the field expects. Use date() to reformat your date or the DateTime class of whatever CakePHP version you're using.

I think here is the format of datatime you are trying to pass is the issue.
Make it change with PHP date function in proper format (YYYY-MM-DD HH:MM:SS).
date('Y-m-d H:i:s',strtotime($yourdate));
I think this will work in this case.
Thanks.

Very weird that if I am using XAMPP at localhost, it can be store perfectly. But when I launch in live (using IIS), it can't store with this datetime format "2015-10-22T15:42:20+08:00".
So I found out that cakePHP is using:
date(DATE_ATOM)
I change it to:
date('Y-m-d H:i:s')
now is it worked.
Thanks to #burzum and #Chandresh. :)

Related

Rails and MySql datetime behaviour

I just noticed something odd in my Rails application.
When I update a DateTime column with a random value like below code, it automatically generates a wrong DateTime and saves it instead of NULL.
user = AdminUser.last
data = {last_sign_in_at: "1234568!"}
user.update_attributes(data)
And it generates a query like below:
UPDATE `admin_users` SET `last_sign_in_at` = '1234-01-01 04:56:02', `updated_at` = '2018-01-24 21:27:50' WHERE `admin_users`.`id` = 3
Where is that odd DateTime value coming from ? And interestingly it works with that specific random value. Not with something like "invalid!" and "1234568!" .
So is this something to do with MySql or Rails query generation ?
Maybe I am not aware of such things in database, as it is not something I work with regularly .
It looks like rails use Time library to convert your 1234568! and if you try that in rails console like Time.zone.parse('1234568!') you get back a Time object Sun, 01 Jan 1234 00:00:00 UTC +00:00 but if you try to do a Date.parse(1234568!) it throws you an ArgumentError: invalid date error so maybe you can parse using date to avoid that.

MySQL Invalid datetime format

I got this error when I'm trying to insert the value 2016-03-27T03:15:51.213 to the column with the data type 'timestamp' in my Yii1 app:
exception 'CDbException' with message 'CDbCommand failed to execute the SQL statement: SQLSTATE[22007]: Invalid datetime format: 1292 Incorrect datetime value: '2016-03-27T03:15:51.213' for column 'created' at row 1.
The strangest thing, when I try to insert a 2016-03-27T13:15:51.213 value - everythin's ok. What's wrong?
I use OpenServer on my Windows machine with PHP 5.6 and MySql 5.7
Finally I've found the solution. The reason of the problem was on my Windows machine. I had an active option "Automatic transition to winter and summer time".
So, because of this option my computer didn't know about time between 3AM and 4AM when the timezone changes, because when the option is turned on, the given time does not physically exist))) So simple)
When I turned off this option on my PC and reboot it, the message had disappeared from logs.
BTW: this problem won't appear at PCs with Linux and UTC-settings without automatic transitions to winter and summer time.
Hope my answer will be helpful for somebody.
Do something like this. First create a datetime object from the string datetime
$datetime = date("Y-m-d h:i:s", strtotime("2016-03-27T13:15:51.213"));// Output = 2016.03.27 01:15:51
And then use this $datetime in the sql query.

Unparseable date error in Pentaho

I am using Pentaho to insert and update a table in Mysql.
Source database being oracle 11g and destination is Mysql database.
The query for getting max syncronization time from oracle is
SELECT
max(SYNC_TIME) AS LST
FROM Abc_ADM.ORA_SYNC_STATS
where SYNC_TIME is of Timestamp(6) datatype in Oracle in format 01-FEB-70 12.00.00.000000000 AM.
when i use this query and run the job i get error-
could not convert string [${LST}] to date using format [yyyy/MM/dd HH:MM:ss:SS] on offset location 0
unparseable date [${LST}]
What is that i am declaring wrong? please help
Pentaho is asking for a date-format like
yyyy/MM/dd HH:MM:ss:SS
But your Oracle-Output is different:
01-FEB-70 12.00.00.000000000 AM
For Pentaho its a string, no date at all.
It should work by telling Pentaho the Date-Format:
dd-MMM-yy HH.mm.ss
Do this in an input-Step
or by using a select-values ("Meta-data") step after your input
Important:
Type should be "Date" and Format: dd-MMM-yy HH.mm.ss
I can't post screenshots where you could have seen that it works for me.
T [1]: http://i.stack.imgur.com/1AuPW.jpg

MySQL Workbench couldnt set new date type for "DATE"

I'm having a problem with mysql workbench - for some reason it doesn't allow me to set 'DATE' as datatype any record. I'm a total beginner if it comes to mysql but i'm forced to use this program (school relevent). I hope any one of you may be able to help me with this. I uploaded a screenshot with the error.
Thanks in advance
Before setting DATE to not NULL put in default column 0000-00-00
EDIT:
UPDATE `Reparatie`
SET `Datum_reparatie_invoer` = str_to_date( `Datum_reparatie_invoer`, '%Y-%m-%d' );
Do the same for the other column.

The Generation Time is wrong when pint in phpMyAdmin

I using phpMyAdmin 4.4.14 in Win7+Chrome and MySQL 5.6 in Linux.
My timezone is +8
The date command in Linux returns a correct date and time.
When I issue select now() inside the phpMyAdmin, the date and time is correct.
But, when I print the result, the time value in the Generation Time is wrong.
Look like that the Generation Time does not do a +8 to the hour.
How to fix ?
Cheers,
Alvin SIU
Print view is done via PHP script, so the issue is in PHP, not in MySQL. In order to change this timestamp, you need to open php.ini and to change/add date.timezone variable with desired value:
[Date]
; Defines the default timezone used by the date functions
; http://php.net/date.timezone
date.timezone = "Europe/Paris"
All available timezones can be found here:
http://www.php.net/manual/en/timezones.php