how to change the timestamp format in other language PostgreSQL - postgresql

PostgreSQL timestamp:
begin= '2018-06-07 08:29:49'
end = '2018-06-10 04:07:57'
QUERY:
select sa.\"end\"::timestamp(0) - sa.begin::timestamp(0)
from tabelle sa;
Output:
2 days 19:38:08
I would like to change this output "days" into "Tage", like:
2 Tage 19:38:08
Most important, when there is month different then it should display months in 'Monate', the same goes for years to 'Jahre'.
i tried to look about dateformat, but i need to change expr format not format like '%Y %m %d ...etc.
i tried this too:
to_char(extract(year from (sa."end"::timestamp - sa.begin::timestamp)),'00')||' Jahre '||to_char(extract(month from (sa."end"::timestamp - sa.begin::timestamp)),'00')||' Monate '||to_char(extract(day from (sa."end"::timestamp - sa.begin::timestamp)),'00')||' Tage '||to_char(extract(hour from (sa."end"::timestamp - sa.begin::timestamp)),'00')||':'||to_char(extract(minute from (sa."end"::timestamp - sa.begin::timestamp)),'00')||':'||to_char(extract(second from (sa."end"::timestamp - sa.begin::timestamp)),'00')
Output:
00 Jahre 00 Monate 02 Tage 19: 38: 08
it doesn't look good, cause month or year shall appear if there is number.
Important, only this 'day' needed to be changed in 'Tage' not setting character UFT8 or other things complete in german language!!!
Please i need your support.

There is some solution but in other way:
select extract(day from (sa.\"end\"::timestamp - sa.begin::timestamp))||' Tage '||
to_char(extract(hour from (sa.\"end\"::timestamp-sa.begin::timestamp)),'00')||':'||
to_char(extract(minute from (sa.\"end\"::timestamp - sa.begin::timestamp)),'00')||':'||
to_char(extract(second from (sa.\"end\"::timestamp - sa.begin::timestamp)),'00')
from tabelle sa
Output:
2 Tage 19: 38: 08

Related

How to use formatDateTime in Azure Data Factory?

I would like to format the pipeline trigger time in this format:
10-Mar-2021 08:31:59 AM
Here is the code I am using:
#formatDateTime(pipeline().TriggerTime, 'DD-MON-YYYY HH:MI:SS AM/PM')
However the date is coming out in this format:
'DD-3ON-YYYY 08:3I:SS A3/P3'
How can I resolve this?
The formatDateTime function uses the custom date format strings which you can see listed here. A detailed breakdown
dd - the day of the month from 01 to 31. Note this is lower case and this format gives a leading 0. Using d for no leading 0
MMM - the abbreviated name of the month, eg JAN, FEB, MAR. Note this is upper case
yyyy - the year as a four-digit number. Note this is lower case
hh - the hour using a 12-hour clock from 01 to 12. Note this is lower case. As you are using AM/PM it makes sense to have the 12-hour clock rather than 24 (ie 23:00 PM would not make sense). Note this is lower case
mm - the minute from 00 to 50. Note this is lower case
ss - the second from 00 to 50. Note this is lower case
tt - the AM/PM designator. Note this is lower case
So using this information, your code should be more like this:
#formatDateTime(pipeline().TriggerTime, 'dd-MMM-yyyy hh:mm:ss tt')
I have test the expression using a Set Variable activity and got the following results:
EEE : Day ( Mon )
MMM : Month in words ( Dec )
MM : Day in Count ( 324 )
mm : Month ( 12 )
dd : Date ( 3 )
HH : Hours ( 12 )
mm : Minutes ( 50 )
ss : Seconds ( 34 )
yyyy: Year ( 2020 ) //both yyyy and YYYY are same
YYYY: Year ( 2020 )
zzz : GMT+05:30
aa : ( AM / PM )

Is there a way to make custom date formats in Julia?

I would like to be able to convert
"Tue Sep 01 00:00:26 +00:00 2020"
into a date type in Julia using the built in Date function.
I only need the year, month, and date.
This is tricky because you have a time zone here hence you need to use TimeZones.jl
using TimeZones, Dates
df = Dates.DateFormat("e u d H:M:S z y");
d = ZonedDateTime("Tue Sep 01 00:00:26 +00:00 2020", df)
Let se what we got:
julia> d = ZonedDateTime("Tue Sep 01 00:00:26 +00:00 2020", df)
2020-09-01T00:00:26+00:00
julia> Date(d)
2020-09-01
For more try typying ?DateFormat in the console - you will see the docs.
Code Matches Comment
–––––––– ––––––––– ––––––––––––––––––––––––––––––––––––––––––––––––––––––––––
y 1996, 96 Returns year of 1996, 0096
Y 1996, 96 Returns year of 1996, 0096. Equivalent to y
m 1, 01 Matches 1 or 2-digit months
u Jan Matches abbreviated months according to the locale keyword
U January Matches full month names according to the locale keyword
d 1, 01 Matches 1 or 2-digit days
H 00 Matches hours (24-hour clock)
I 00 For outputting hours with 12-hour clock
M 00 Matches minutes
S 00 Matches seconds
s .500 Matches milliseconds
e Mon, Tues Matches abbreviated days of the week
E Monday Matches full name days of the week
p AM Matches AM/PM (case-insensitive)
yyyymmdd 19960101 Matches fixed-width year, month, and day
To parse dates you need the Dates.jl standard library. To parse this particular format though, I think you additionally need the TimeZones.jl package:
using Dates
using TimeZones # gives the `z` for the format below
fmt = dateformat"e u d H:M:S z y" # the format of your string
d = Date("Tue Sep 01 00:00:26 +00:00 2020", fmt)
Then you can simply look at d's values for example with:
julia> d
2020-09-01
julia> year(d)
2020
julia> month(d)
9
julia> day(d)
1

Convert Mo-Sa and Mo-Fr to: Mo, Tue, Wed, ... -columns

I want to transform following Column:
Col_openingHours:
1: Mo-Sa: 03:00 - 11:00
| 2: Mo-Sa: 02:00 - 10:00
into:
Col_monday:
1: 03:00 - 11:00 |
2: 02:00 - 10:00
Col_tuesday:
1: 03:00 - 11:00 |
2: 02:00 - 10:00
...
How i can get this in Dataprep?
I also have some values in the col1 like "Mo-Fr". And then de Col_saturday has a different columns as source than the showed example (e.g.: Col_openingHours2).
I tried convert values to Columns, but it seems like the wrong tool.
Then i tried to create new columns like col_monday and wanted to set the values with "If(equal (col-openingHours, "Mo-Sa"), ... ) ..
(For this i splitted the cell [Mo-Sa |split| 03:00 - 11:00])
But that wasnt the right tool, too i think.
would be very happy for helping me :)
The most straightforward way to handle this would be to turn your openingHours column into a quick JSON object, so you'd have something like
{
"1": [{
"Mon": "03:00 - 11:00",
"Tues": "03:00 - 11:00",
"Weds": "03:00 - 11:00"
}],
"2": [{
"Mon": "02:00 - 10:00",
"Tues": "02:00 - 10:00",
"Weds": "02:00 - 10:00"
}]
}
This should be achievable by using text pattern replacements and a bit of regex as needed. Once that's done, you can unnest the data itself into columns as you desire, now with the right splits per value.

Can someone show me how I can output hrs:mins:secs in mySQL SELECT statement below?

Here is the picture of how I would like it to be displayed
Here is what I have so far when use the DATE_ADD function in MySQL Workbench 6.3, but I have been struggling to output the hrs:mins:secs (you don't see the code for that output because I didn't write it here). I know that I can use INTERVAL HOUR_SECOND to display hrs:mins:secs but I don't understand how it works.
SELECT DATE_ADD('2017-01-26', INTERVAL 31 DAY) AS '31 Days';
I know this SELECT statement above will output 31 days from the specified date indicated above, but what do I need to do to output the hrs:mins:secs along with the 31 days from the date in the SELECT statement?
You can do it using DATE_FORMAT(). Examples:
Add function
/*
* Adds a particular interval to given date
*/
SELECT DATE_ADD('2017-01-26', INTERVAL 31 DAY) AS '31 Days';
Output:
31 Days
2017-02-26
Format function
/*
* Formats a particular date object
*/
SELECT DATE_FORMAT(NOW(),'%b %d %Y %h:%i %p')
AS 'Now';
Output:
Now
Jan 28 2017 04:29 PM
Format and add:
/*
* Adds and Formats date object
*/
SELECT DATE_FORMAT(DATE_ADD('2017-01-26', INTERVAL 31 DAY),'%b %d %Y %h:%i %p')
AS 'Formatted date';
Output:
Formatted date
Feb 26 2017 12:00 AM
Additionally, here is the sqlfiddle for the example: http://sqlfiddle.com/#!9/9eecb7d/92948
Also check the various formats to further tailor to your needs: http://www.w3schools.com/sql/func_date_format.asp

between date cakephp 3

when I make a between a date and see the log this adds spaces
$campaigns = TableRegistry::get('Administrator.Campaigns');
$campaignsActual= $campaigns->find('All')
->where('parent_id IS NULL AND '.date("Y-m-d").' BETWEEN start AND end')
but
SELECT
Campaigns.id ASCampaigns__id,
Campaigns.name ASCampaigns__name,
Campaigns.description ASCampaigns__description,
Campaigns.start ASCampaigns__start,
Campaigns.end ASCampaigns__end,
Campaigns.status ASCampaigns__status,
Campaigns.parent_id ASCampaigns__parent_id,
Campaigns.lft ASCampaigns__lft,
Campaigns.rght ASCampaigns__rght,
Campaigns.created ASCampaigns__created,
Campaigns.modified ASCampaigns__modified
FROM
campaigns Campaigns
WHERE
parent_id IS NULL
AND 2017 - 01 - 23 BETWEEN start
AND end
The date 2017 - 01 - 23 generates spaces How to ensure that these spaces are not converted?
The problem is ->where('parent_id IS NULL AND "'.date("Y-m-d").'" BETWEEN start AND end')
"'.date("Y-m-d").'"