Date Format in pg-node - node.js

I have tried to insert date into the postgresql in 'dd.mm.yyyy' format.
First inserted the string type, then the date type
moment(new Date()).format('DD.MM.YYYY') but in database format always like 'yyyy-mm-dd'
What can I do?
Plesase, help

Related

Convert to required date format with date datatype

I have input col as 12/03/08 viz dd/MM/yy . So I beed it in the format of dd/MM/yyyy . SO I have use the below transformation as :
toString(toDate(col,'dd/MM/yy'),'dd/MM/yyyy')
This works fine.
But at the end i need to conver this col to date datatype with the same format as dd/MM/yyyy . When i do the CAST transformation like
In cast , i have converted it to date and given the format as dd/MM/yyyy .Its giving the date but in default format like dd-MM-yyyy . I need slashes instead of dashes.
I tried to do
toDate( col, 'dd/MM/yyyy') ,Still i get the default format dd-MM-yyyy.
How to fix this.
When you CAST in SQL for conversion, the resulted format is determined by the default format of your database. If you want to ensure that the date is formatted in a specific way, you can use the DATE_FORMAT function in combination with the toDate function.
If you want to get the wanted dd/MM/yy to the format dd/MM/yyyy, you can use the following transformation:
toString(toDate(col, 'dd/MM/yy'), 'dd/MM/yyyy')
This first converts the string to a type using toDate and then formats itt as a string with the wanted format using the toString function.
However, if you then want to convert the string column back to a date datatype with the format dd/MM/yyyy, you cant simply use the CAST function with the desired format, as the resulting format will still be determined by the default format of your database. Instead, you can use the DATE_FORMAT function to format the date as a string with the desired format, and then convert it back to a date datatype using the toDate function.
To convert the string column col back to a date datatype with the format dd/MM/yyyy, you can use the following transformation:
toDate(DATE_FORMAT(col, 'dd/MM/yyyy'), 'dd/MM/yyyy')
This first formats the date in your string column as a string with the desired format using the DATE_FORMAT function, and then converts it back to a date datatype with the same format using the toDate function.

ADF: How to Convert a datetime column (AM/PM) to UTC format?

I have a column where timestamp is 5/23/2022 8:45:34 PM. I want to create a new column with same data as old column but in UTC format 'yyyy-MM-dd HH:mm:ss' and this new datetime format is 7 hours behind UTC (UTC-7)
I tried doing in azure data factory derived column using toTimestamp before it converts to UTC but it always fail.
toTimestamp(column_name,'yyyy-MM-dd HH:mm:SS')
but it did not work and the result always NULL.
Can anyone help this data conversion to UTC ?
The reason you are getting null values for the newly added columns is because the format you specified in the toTimestamp() function is incorrect. The following is the sample data that I used to reproduce this issue. The date column here is of type String.
While using Derived column in the dataflow to create a new date column of timestamp type, write toTimestamp(date, 'MM/dd/yyyy hh:mm:ss a', 'UTC') expression as the value for this new column. Here, date is the column you want to convert to new date column and MM/dd/yyyy hh:mm:ss a is the format of the values in date column (a represents the AM/PM). You can also pass time zone value like UTC, GMT etc. which is optional.
The following is what the result looks like, with a new column of timestamp type. You can use this resulting data to perform further conversions in dataflow.

Convert a varchar column to date for the month of December

I have a varchar2 column in a table which saves dates in it with the format mask 'DD-MON-RR'.
Now when I try to convert it with
{to_date(my_field,'DD-MON-RR')}
it returns accurate result except when I convert the December month, it throws an error
literal does not match the format string
I have solved my problem by converting whole string to {to_char} again, but my question is: why does Oracle not let me convert the month of December saved in form of 'DEC'?

How to convert a string datatype column to date format in hive

Could you please guide with below query.
I need to convert below string column to date.
Input and expected output is provided in screenshot.
Input table: column maturity_date is in string datatype.
I tried below but not working as expected
to_date(from_unixtime(unix_timestamp(maturity_date,'MM/DD/YYYY H:mm:ss'),'yyyy-mm-dd')
Try using lower case letters. Upper case means another thing (day of year (D) and week-year (Y)).
to_date(from_unixtime(unix_timestamp(maturity_date,'MM/dd/yyyy H:mm:ss'),'yyyy-MM-dd')
Correct input format is 'MM/dd/yyyy H:mm:ss', not 'MM/DD/YYYY H:mm:ss'
Correct output format is yyyy-MM-dd, not yyyy-mm-dd. mm is minutes. MM is month
Read more about date format used in Hive here SimpleDateFormat

Parsing non iso datetime string to just date part in presto

I have table which stores datetime as varchar
Format looks like this 2018-07-16 15:00:00.0 ,
I want to parse this to extract only date part so that I use date part to compare with date in string format such as '2018-07-20' in where clause. What is the best way to achieve this in presto?
This particular format (based on example value 2018-07-16 15:00:00.0 in the question) is understood by cast from varchar to timestamp. You then need to extract date part with another cast:
presto> SELECT CAST(CAST('2018-07-16 15:00:00.0' AS timestamp) AS date);
_col0
------------
2018-07-16
(1 row)

Resources