I´ve several dates wich are stored in my database like this: 2016-02-17.
I want them to be displayed like this: 17.02.2016.
For this I use this code in my AppController:
I18n::locale('de-DE');
Time::$defaultLocale = 'de-DE';
Time::setToStringFormat('dd.MM.YYYY');
Type::build('datetime')->useLocaleParser()->setLocaleFormat('dd.MM.YYYY');
But my output always looks like this: 17.02.16.
How do I force the output of the year with 4 characters?
Many thanks in advance. :)
Try using date("d.m.Y", strtotime($yourDateAsStringFromDb)). This will return the date formatted as you describe you want it.
I just tryed using this and it works to display the date as you asked.
bare in mind in this capital letters matter
Related
I have some fields in a MYSQL database with the following content:
eq":"fieldname1+fieldname2+fieldname3+fieldname4/4
The numbers are always different, so it could also be something like:
eq":"fieldname11+fieldname22+fieldname8/10
I would like to run a query to achieve the following:
eq":"((fieldname1+fieldname2+fieldname3+fieldname4)/4, 2)
I currently have the following query
UPDATE wp_wrdydtdbww_cp_calculated_fields_form_settings
SET form_structure = REPLACE(form_structure, '???', '???')
WHERE id IN (1,2,3);
The problem is, that there are a lot of additional strings, containing 'fieldname' or '/' as well, so I need to replace the exact structure.
Can somebody help me to modify it?
I tried something with the LIKE pattern (%), but can't get it to work as I always replace other parts of strings as well.
Thanks!
I have an application where I can download data to excel file.
The problem is that I need to add euro sigh to some fields.
I had a simialar problem with date.
In excel it was 54656434
It changed in normal date after using convert(varchar,senddate,105)
Is there something that looks like that to add euro sign and round it to 2 decimals ???
EDIT:
In excel i get the number like 1,55435
I need the output be like € 1,55
This is kind of convoluted... let me know what you think. Replace '1,55435' with your field.
SELECT CONCAT('£', CAST(CAST(1,55435 AS DECIMAL(18,2)) AS CHAR(55)))
I'm in the US, so I'm not sure if decimals can be changed to use commas instead of periods.
Edit: Also, try this: SELECT CONCAT('£', FORMAT(1,55365, 2)). Let me know which works.
I'm trying to convert a date type column into a nice human readable string like so: 25/11/2016 (or any other masks I'd like to use)
Does Big Query supports masks when using dates? When I use the Date() Functions it returns something like "2016-05-05" but that's not the standard pattern in many countries.
I've searched for a lot of different things the closes thing I got is this doc: https://cloud.google.com/bigquery/query-reference but I didn't see anythin that would help me
check STRFTIME_UTC_USEC
SELECT STRFTIME_UTC_USEC(CURRENT_DATE(), '%d/%m/%Y')
Simple question
What is the best way to change the output so that it only displays the last two decimals?
SELECT AVG(TIMESTAMPDIFF(hour, start_it,start_qa)
So that the output of '13.2500' displays as '13.25'.
Thanks for your help.
Normally, you would do this in the application layer. If you insist on doing it in the database, you can use format():
SELECT FORMAT(AVG(TIMESTAMPDIFF(hour, start_it,start_qa), 2)
In MYSQL database, the title row is this:
Interview: Gus O\'Connor win
I am trying to search
title LIKE '%O\'Connor%'
I tried everything and still came up empty, no results returned.
I have tried
'%O''Connor%'
and
\"%O'Connor%"\
and yes, i am protecting myself from sql injection with code above.
You may try like this:
title LIKE "%O\\'Connor%"
If your database entry actually contains that backslash, you'll need to use this:
title LIKE "%O\\'Connor%"
Not sure why you are setting up a SQL string like this given the new PDO frame work which does allow not this syntax but anyways, try
LIKE "%O\\'Connor%"