cakephp3 date_format error: Call to a member function format() on boolean FrozenTimeTrait.php - date-formatting

fnacimiento and ffallecimiento is date in the table
$personas = TableRegistry::get('Personas')->find();
$personas = $personas->select([
'fnacimiento' => 'date_format(fnacimiento, "%d/%m/%Y")',
'ffallecimiento' => 'date_format(ffallecimiento, "%d/%m/%Y")']);
$this->set('personas', $personas);
I want to move from 0000-00-00 to 00/00/0000 (YYYY-MM-DD to DD/MM/YYYY)
But it is not working it gives me this error:
Error: Call to a member function format() on boolean File
...vendor/cakephp/chronos/src/Traits/FrozenTimeTrait.php Line: 161
The query is fine, because in mysql it works, but cakephp has some problem with the format, I do not understand it.

Related

Scala code: Getting type mismatch error when using substring spark sql function?

Error occurs at (instr(col("manuscriptpolicy_ext_vehicledescription"),"Registration No.:")+17) since it detects the type to be column and not int as the substring function input is substring(string, int, int). Ive tried casting it to be int but it still detects it as a column. Am I doing something that's causing it to be detected as a column?
val registrationNumber = pc_policy_df.select(col("vehicledescription"),
when(col("subproduct_ext")==="SpecialRiskOwnDamage" &&
instr(col("vehicledescription"),"Registration No.:")===0, "")
.when(col("subproduct_ext")==="SpecialRiskOwnDamage" &&
instr(col("vehicledescription"),"Registration No.:")>0, trim(substring(col
("vehicledescription"),(instr(col("manuscriptpolicy_ext_vehicledescription"),
"Registration No.:")+17),locate(";",col("vehicledescription"),instr
(col("vehicledescription"), "Registration No.:")+17)-(instr
(col("vehicledescription"),"Registration No.:") +17) )))
.otherwise("registrationnumber"))
.as("R_NUMBER")
}
You input to the trim function should look more like:
trim(
col("vehicledescription")
.substr(
instr(col("manuscriptpolicy_ext_vehicledescription"), "Registration No.:"+ lit(17)),
locate(";", col("vehicledescription"))))
The substr method is defined on Column and accepts columns as inputs which is what you want here.

flutter convert date string to int

here I want to display the date in the format yy/MM/dd hh:mm but an error appears
type 'String' is not a subtype of type 'int'
final f = new DateFormat('yy/MM/dd hh:mm');
then
TextSpan(text: f.format(new DateTime.fromMillisecondsSinceEpoch(item["transaction_date"]*1000))),
and already tried using date format
but it's still an error with the same error
I guess your item["transaction_date"] is String. Try to parse it: int.parse(item["transaction_date"])

How to create a datetime in apex given a datetime string?

With apex, I pass a string like:
2017-02-05T01:44:00.000Z
to an apex function from javascript, however, when attempting to turn it into a datetime, it gives me invalid date/time error. I can create a date with it like
date newdate = date.valueOf(dateString);
but if I do datetime newdate = datetime.valueOf(dateString) I get the error. I don't get why it sees the string as incorrectly formatted to give invalid date/time. When I create just a date instead of datetime, I lose the time and it sets it to 00:00:00.
Thank you to anyone with some insight on how to create the datetime in apex! I have been trying to find the apex format and from what I see. I can't understand why it thinks this is invalid.
Try this.
String inpputString = '2017-02-05T01:44:00.000Z';
DateTime resultDateTime = DateTime.ValueofGmt(inpputString.replace('T', ' '));
System.Debug('resultDateTime>> '+resultDateTime);
Output:
10:10:41:011 USER_DEBUG [4]|DEBUG|resultDateTime>> 2017-02-05 01:44:00

How to pass a null value received on msg.req.query to msg.payload

I am developing an application using Dashdb on Bluemix and nodered, my PHP application uses the call to webservice to invoke the node-red, whenever my function on PHP invokes the node to insert on table and the field GEO_ID is null, the application fails, I understand the issue, it seems the third parameter was not informed, I have just tried to check the param before and passing something like NULL but it continues not working.
See the code:
msg.account_id = msg.req.query.account_id;
msg.user_id = msg.req.query.user_id;
msg.geo_id=msg.req.query.geo_id;
msg.payload = "INSERT INTO ACCOUNT_USER (ACCOUNT_ID, USER_ID, GEO_ID) VALUES (?,?,?) ";
return msg;
And on Dashdb component I have set the parameter as below:
msg.account_id,msg.user_id,msg.geo_id
The third geo_id is the issue, I have tried something like the code below:
if(msg.req.query.geo_id===null){msg.geo_id=null}
or
if(msg.req.query.geo_id===null){msg.geo_id="null"}
The error I got is the one below:
dashDB query node: Error: [IBM][CLI Driver][DB2/LINUXX8664] SQL0420N Invalid character found in a character string argument of the function "DECIMAL". SQLSTATE=22018
I really appreciate if someone could help me on it .
Thanks,
Eduardo Diogo Garcia
Is it possible that msg.req.query.geo_id is set to an empty string?
In that case neither if statement above would get executed, and you would be trying to insert an empty string into a DECIMAL column. Maybe try something like this:
if (! msg.req.query.geo_id || msg.req.query.geo_id == '') {
msg.geo_id = null;
}

CakePHP FormHelper Input Date

I have following question. When I use this Helper:
echo $this->Form->input('start_date', array('required'=>false, 'class'=>'form-control date'));
I get following output:
Where can I change this output type? I tried it in
/lib/Cake/View/Helper/FormHelper.php
I found in this lib file, that the Helper gets the function __getInput() and in the date case, following sub function:
case 'date':
$options['value'] = $selected;
return $this->dateTime($fieldName, $dateFormat, null, $options);
But in the function dateTime() I got lost. Is there any updated Helper out or is there a simple trick to change the HTML-output format?
Thanks & regards
Set input type as text
echo $this->Form->input('start_date', array('type'=>'text','required'=>false, 'class'=>'form-control date'));