Regex in postgres to extract datetime from text column - regex

I have a column that has multiple comments along with some DateTime stamps. The example is like this:
abc#gmail.com - 03/03/2022 13:04:40
Documents Pending
Some random comment
I want to extract only the DateTime stamp from this column. I tried using to_char, and to_date functions in PostgreSQL, but none of it seems to work for me.
I also tried writing a regex to extract the DateTime stamp, but it didn't work.
What is the correct way to extract only DateTime from the above column? What would be the regular expression to extract the DateTime?
Thanks in advance.
Edit: I want to extract a date from a column like this:
abc#gmail.com - 12-Aug-2022
Documents Pending
Some random comment
How we can identify the month number or a date format from this comment?

You could use SUBSTRING() here:
SELECT col,
SUBSTRING(col FROM '\y\d{2}/\d{2}/\d{4} \d{2}:\d{2}:\d{2}\y') AS ts
FROM yourTable;

Related

How to do text based filtering on DateTimeFields using a specific template format?

I have a table that includes both CharFields and DateTimeFields displayed using django template language. The DateTimeFields are displayed in the format "Aug. 18, 2020, 6:33 p.m.". Is there an easy way to do a text based filter/query on the DateTimeFields based on that specific format? For example, searching "aug" or "Aug" or "Aug. 18" or "2020" should find that entry.
I've tried icontains, but that seems to work on the underlying format, rather than the display format. For example, searching "2020-08" finds that entry, but searching "Aug" does not.
Works:
Entry.objects.get(created__icontains='2020')
Entry.objects.get(created__icontains='2020-08')
Entry.objects.get(created__icontains='33')
Does not work:
Entry.objects.get(created__icontains='Aug')
Entry.objects.get(created__icontains='6:33')
Entry.objects.get(created__icontains='p.m')
Is there a way to search the using the specific dat time display format?
What format is the underlying DateTimeField? Is it DB dependent?
Partial answer for 2: the underlaying format seems to be UTC in the format
"2020-05-12 18:58:23.210862+00". Using icontains on any of that text works.
For clarification, the idea is to search all fields (datetime and string) with the same text. So, "Aug" should return a row that has a date field with "Aug 13" or a string field with "Augustine". Kind of like a general google search.
you have change string to datetime,
like this:date = datetime.date(2020, 8, 3) ,
here is you can use:
date:Entry.objects.filter(created__date=datetime.date(2005, 1, 1))
year:Entry.objects.filter(created__year= 2020)
month:Entry.objects.filter(created__month=8)
hour:Event.objects.filter(created__hour=6)
minute:Event.objects.filter(created__minute=29)
second:Event.objects.filter(created__second=31)
you can see more about date querysets on here:https://docs.djangoproject.com/en/3.1/ref/models/querysets/#year

CFSpreadsheet not formatting dates

I think I have read just about every post on this topic and none of the proposed solutions works in my case so here goes.
I am using CF9 (upgrade not an option) for this project. I query a date field from a MSSQL database and use spreadsheetAddRows() to put the results into a spreadsheet (xls or xlsx, same result either way).
The date shows in excel as 2020-05-11 00:00:00.0 and isn't recognised as a date so the date formatting doesn't work.
I have tried using SpreadsheetFormatColumn (s, { dataformat="d-mmm-yy" }, 2); but this doesn't format the date either and has the exact same result in excel.
I have tried many variations of selecting convert(varchar, datecolumn, 101) from the database but these always just end up as text fields in excel as well so again, no date formatting and they sort in the wrong order.
Can anyone tell me what the correct format for a date is for CFSpreadsheet so that excel actually recognises it as a date?

informatica datetime datatype format

I want to convert the string 20160101000000 into datetime format using expression. I have used below date function
TO_DATE(PERIOD_END_DATE),'MM/DD/YYYY HH24:MI:SS')
But my table file is not loading. My session and workflow gets succeed. My target and source is also flatfile.
I want to change the string 20160101000000 into MM/DD/YYYY HH24:MI:SS for loading data into my target table.
You need to give exact format that looks so that to_date function can understand that format and converts it into date.
TO_DATE(PERIOD_END_DATE,'YYYYMMDDHH24MISS')
So here your date looks like YYYYMMDDHH24MISS (20160101000000).
There is often confusion with the TO_DATE function... it is in fact for converting a string into a date and the function itself is to describe the pattern of the incoming date. Now if you want to convert a date field to a specified date format you must use TO_CHAR

DAX - how to convert a date string from another locale into a date type

I have a date string that fails to import because it is in a different format to that expected my the machines locale (i.e. US dates to a UK machine).
How do I tell DAX to convert this string into a date, but using a specified format or locale, different to the machines default.
For example, I would like to import
3/27/2008 11:07:31 AM
as
27/3/2008 11:07:31 AM
You have two options.
First option, use the basic Formatting tab functionality in Power BI.
Select the column and use the below settings in the Formatting tab:
Second option (recommended), use PowerQuery to import the text column in datetime data type.
The following expression will split the text by "/" character, then will convert dd/mm/yyyy string to the datetime data type.
Table.AddColumn(#"Changed Type", "DateTime",
each Text.Split([#"#(001A)Date Import"],"/"){1} & "/"
& Text.Split([#"#(001A)Date Import"],"/"){0} & "/" &
Text.Split([#"# (001A)Date Import"],"/"){2})
In this case I've added an additional column in order to import the column in the required datetime type, you can apply the changes to the same column though.
Date import column is the actual text column, DateTime is the column I've added to import Date Importas Datetime type.
If you get stuck check the official documentation about PowerQuery.
Let me know if this helps.
I think the most practical solution is in the Query Editor, but complex formula are not required.
I would Right-click the column and choose Change Type / Using Locale. Then I would specify Data Type = Date and Locale = English (United States).

Python pandas convert (yy/mm) date format and select certain time range

guru, i am reading a big table with a column "issue_day" in "yy-mm" format. For example:
status issue_day
active 11-Dec
inactive 10-Dec
active 9-Dec
active 8-Jun
Is there any pythonic/pandas way to select data earlier than 2011? (For example, we only want data in 10-Dec & 09-Dec in this case). There is only "dayfirst" in the pandas to_csv command, but I don't see "yearfirst". Could any guru enlighten? Thank you
What about this?
df=pd.DataFrame(['11-Dec','10-Dec','09-Dec'],columns=['issue_day'])
df['issue_day']=pd.to_datetime(df['issue_day'],format="%y-%b")
print df[df['issue_day']<'2011']