Issue in converting String datetime to timestamp In Azure Data Flow - azure

I have done the following in derived column to convert string column to timestamp
toTimestamp({QIR Date},'yyyy-MM-dd HH:mm:ss')
i/p col has 2021-01-26 11:44:45
I am getting O/p as 2021-01-26 11:44:45.000
I need to eliminate last zeros coming.I know we can do like :
toString(toTimestamp({QIR Date},'yyyy-MM-dd HH:mm:ss'),'yyyy-MM-dd HH:mm:ss')
But i need the datatype as timestamp at the end . Conversion is adding 000 at the end . Can anyone help or am I approaching this wrong.

You can try rtrim(toTimestamp({QIR Date},'yyyy-MM-dd HH:mm:ss'),'000')

Related

Need an alternate approach for Out of bounds nanosecond timestamp Error in Python

I have two columns in excel - effectivedate and expirationdate. I am using a for loop and reading the column values from the excel using Pandas dataframe.
Df[date1] = pd.to_datetime(Df[date1]).dt.strftime("%m/%d/%Y %H:%M:%S.0")
Here date1 is the column value from excel like effectivedate, expirationdate.
This syntax is working fine for the effectivedate and the output for effectivedate is given below:
10/01/2020 00:00:00.0
But for expirationdate, it is not working. I am getting the below error:
Error: pandas._libs.tslibs.np_datetime.OutOfBoundsDatetime: Out of bounds nanosecond timestamp: 2999-12-31 00:00:00
Looks like there is a limit of year and hence getting the error. After adding errors='coerce', I am not getting the error, but the output column has no value and getting NaN.
Df[date1] = pd.to_datetime(Df[date1],errors='coerce').dt.strftime("%m/%d/%Y %H:%M:%S.0")
Could you please suggest an alternative way to get the expirationdate in the
format 12/31/2999 00:00:00.0?

spark dataframe: date formatting not working

I have a csv file in which a date column has values like 01080600, basically MM-dd-HH-mm.
I want to add a column in dataframe which shows this in a more readable format.
I do :
spark.sql("SELECT date...")
.withColumn("readable date", to_date(col("date"), "MM:dd HH:mm"))
.show(10)
But readable date is returned null.
What am I missing here?
While formating or converting to date or timestamp you need to provide the date_format as is following your pattern , example in your case you need to modify your format as below and further which can be formatted depending on the final format you wish your date col to take using date_format
References to various patterns and parsing can be found here
To Timestamp
sql.sql("""
SELECT
TO_TIMESTAMP('01080600','ddMMhhmm') as date,
DATE_FORMAT(TO_TIMESTAMP('01080600','ddMMhhmm'),'MM/dd hh:mm') as formated_date
""").show()
+-------------------+-------------+
| date|formated_date|
+-------------------+-------------+
|1970-08-01 06:00:00| 08/01 06:00|
+-------------------+-------------+

Azure Data Factory v2 Mapping Data Flow - ticks () to TimeStamp datetime format

Requirement:
I'd like to transform CSV file using ADF Mapping data flow.
I have a string column containing data in ticks date format that I want to transform into Date time.
Source
ticks_date
batch_id
637842420600000000
100010
637834825200000000
100005
Sink
timestamp
batch_id
2022-03-30​T13:01:00.000Z
100010
2022-03-21​T18:02:00.000Z
100005
https://tickstodatetime.azurewebsites.net/
I've tried to convert the ticks value to UNIX Epoch timestamp and used the below expressions which I got from different thread but I'm getting null values.
toTimestamp(toLong(toInteger(toString(byName('ticks_date')))),'yyyy-MM-dd HH:mm:ss')
toTimestamp(seconds(toInteger(toString(byName('ticks_date')))),'yyyy-MM-dd HH:mm:ss')
I'm a newbie to ticks format and stuck here couple of days.
Appreciate if someone can guide me to resolve the issue.
There are two approaches you can follow:
Create datetime object with a specific value of ticks
DateTime myDate = new DateTime(numberOfTicks);
String test = myDate.ToString("MMMM dd, yyyy");
Much simpler manner
DateTime dt = new DateTime(633896886277130000);
Which may give output like below
"9/27/2009 10:50:27 PM"
Kindly refer the below link
https://devkimchi.com/2018/11/04/converting-tick-or-epoch-to-timestamp-in-logic-app/

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

How to convert string to datetime format if it is in a list?

I am trying to plot a graph with dates format. The thing is that I have problem with the format of the dates column.
I have tried to use the solution like this:
df['Date'] = pd.to_datetime(df['Date'])
It works. But the problem is that when I append the value of the Date in the dataframe into a list, the format of my Date column turns back to String. How do I solve this case?
hope this will work
solution1
df['Date']=df['Date'].astype('datetime64[ns]')
Solution2
date is the list of date in string formate,if u want to convert into datetime then try this code
dates_list = [dt.datetime.strptime(date, '"%Y-%m-%d"').date() for date in dates]

Resources