How to reformat this datetime without regex in Google Sheets? - regex

In Google Sheets i want to reformat this datetime Mon, 08 Mar 2021 10:57:15 GMT into this 08/03/2021.
Using RegEx i achieve the goal with
=to_date(datevalue(REGEXEXTRACT("Mon, 08 Mar 2021 10:57:15 GMT","\b[0-9]{2}\s\D{3}\s[0-9]{4}\b")))
But how can i do it without RegEx? This datetime format seems to be a classic one - can it really be, that no onboard formula can't do it? I rather think, i miss the right knowledge here...

Please try the following formula and format as date
=TRIM(LEFT(INDEX(SPLIT(K13,","),,2),12))*1
(do adjust according to your locale)

Another option is to use Custom Script.
Example:
Code:
function formatDate(date) {
return Utilities.formatDate(new Date(date), "GMT", "dd/MM/YYYY")
}
Formula in B1: =formatDate(A1)
Output:
Reference:
Custom Functions in Google Sheets

Related

display regular date for FormattedRelative

I want to display friendly format date just like whatsapp and telegram do. For example, for today's date it shows "today" and yesterday date it shows "yesterday". But I don't want to show three days before as "3 days ago". It should be the regular date like this "Sun, 7 Jul 2019".
I don't have any custom to the current code because it still uses the example from the repo. But I tried to change the format but none of that works.
What does your code look like? You'd have to do some logic like
if (daysAgo > -2) {
return <FormattedRelativeTime numeric="auto" unit="day" value={daysAgo} />
}
return <FormattedDate weekday="short" day="numeric" month="short" year="numeric" value={ts} />

If and REGEXTRACT

I have a text (see below) where
I would like to extract the date only for the specific status, when the date appears after "New on Date".
I want the formula to answer: if the status is "New" then extract the "date".
I tried this: =If(A2 = "New",REGEXEXTRACT(A2,"(\d{1,}?\/\d{1,}?\/\d{4})"),)
I also tried the same by adding Find and Search but still unsuccessful.
I know that this part of the formula works: REGEXEXTRACT(A2,"(\d{1,}?\/\d{1,}?\/\d{4})")
But I do not manage to find the other part: Would anyone have a guess?
Contract Rejected/Contract Withdrew on Date: 11/11/2016 6:23:33 AM and Modified by: Eletttt|| Offer Negotiation on Date: 6/2/2016 5:36:04 AM and Modified by: Dexx|| HR Screening on Date: 4/14/2016 2:30:57 AM and Modified by: Dexxx|| New on Date: 4/14/2016 2:24:58 AM and Modified by: Dexxx|| Contract sent on Date: 6/7/2016 11:03:58 AM and Modified by: Chrisyyy|| Pending Contract Approval on Date: 6/7/2016 4:56:55 AM and Modified by: Debxxx|| HM Interview on Date: 5/10/2016 12:40:30 AM and Modified by: Debxxx
If you need to extract the date after New on Date, you need to add this text to the pattern and keep the capturing group where it is now:
=REGEXEXTRACT(A2, "New on Date:\s*(\d{1,2}/\d{1,2}/\d{4})")
See the screenshot (with the data inside B29 cell):
See the regex demo.
Here is a simpler one for you:
=REGEXEXTRACT(A1,"New on Date:\s(\d\S+)")

How to use regular expression in hbase

I am new to HBase and trying to do some scan query. Below is my sample data:
2470883371 column=card info:CARD_TYPE, timestamp=1439291958723, value=MASTERCARD
2470883371 column=card info:UNIQUE_NO, timestamp=1439291958767, value=991-761-828-450
2470883371 column=card info:EXPIRY_DATE, timestamp=1439291958747, value=Wed Oct 03 18:09:34 IST 2018
3495415072 column=card info:CARD_TYPE, timestamp=1439291958835, value=MASTERCARD
3495415072 column=card info:UNIQUE_NO, timestamp=1439291959618, value=973-470-914-600
3495415072 column=card info:EXPIRY_DATE, timestamp=1439291958850, value=Wed Oct 03 18:09:34 IST 2018
I want to query like:
Retrive all results that start from rowkey id 2470883 (actual value is 2470883371)
Retrive all results whose unique number starts from 991-761-828 (actual value is 991-761-828-450)
Is it possible in HBase using scan? Basically I want to know how to use a regular expression.
Take a look at Filters and Comparators, for example RegexStringComparator https://hbase.apache.org/0.94/apidocs/org/apache/hadoop/hbase/filter/RegexStringComparator.html
This regular expression should match what you need:
((?:^2470883.*?$)|(?:^.*?value=991-761-828.*?$))

Regex for getting the date

The query
SELECT REGEXP_SUBSTR('Outstanding Trade Ticket Report_08 Apr 14.xlsx', '\_(.*)\.') AS FILE_DATE FROM DUAL
gives the OUTPUT:
_08 Apr 14.
Please advise the correct regex to be used for getting the date without the characters.
I can use RTRIM and LTRIM but want to try it using regex.
You can use:
SELECT REGEXP_SUBSTR('Outstanding Trade Ticket Report_08 Apr 14.xlsx', '\_(.*)\.',
1, 1, NULL, 1) from dual
The last argument is used to determine which matched group to return.
Link to Fiddler

Extract text with regex between ","

I have been struggling making a regex to extract the information in below divided in 3 part between the ",". Only the first and second sequence (Friday and the date has succeded).
Friday, 26 Apr 2013, 18:30
I hope someone has the experience.
Best regards
Why not simply split the string and trim the excess whitespace of the individual parts? For example, verbosely written in C#:
string input = "Friday, 26 Apr 2013, 18:30";
string[] parts = input.Split(',');
for (int i = 0; i < parts.Length; i++)
{
parts[i] = parts[i].Trim();
}
Console.WriteLine(parts[0]); // "Friday"
Console.WriteLine(parts[1]); // "26 Apr 2013"
Console.WriteLine(parts[2]); // "18:30"
If you really want to use a regular expression for this, ^(.*),(.*),(.*)$ should work:
string input = "Friday, 26 Apr 2013, 18:30";
Regex regex = new Regex("^(.*),(.*),(.*)$", RegexOptions.Singleline);
Match match = regex.Match(input);
Console.WriteLine(match.Groups[1].Value.Trim()); // "Friday"
Console.WriteLine(match.Groups[2].Value.Trim()); // "26 Apr 2013"
Console.WriteLine(match.Groups[3].Value.Trim()); // "18:30"
Adding appropriate error checking is left as an exercise for the reader.
The following Regex expression is matching this whole part :
, 18:30
I hope someone has the experience.
Best regards
,+\s[0-9]+:[0-9]+ \r*.*
But yeah, that's kind of ultra specific to this ", Hour:Minuts [...]" format. You should do a split if you're using PHP or the equivalent in your language.
I think what you really want is something like this:
from datetime import datetime
s="Friday, 26 Apr 2013, 18:30"
d=datetime.strptime(s, "%A, %d %b %Y, %H:%M")
d
Out[7]: datetime.datetime(2013, 4, 26, 18, 30)
See the strptime and date format docs for details :)
Edit: sorry, I was somehow assuming you were using Python. Other languages have similar idioms though, e.g. PHP's date_parse, C#'s DateTime.Parse, etc.
You didn't specify a language so I'm going to answer this with a standard REGEX approach.
(?<=(^|,\s+)).+?(?=(,|$)) Will work for you.
Let me break up what it's doing.
(?<=(^|,\s+) - Look ahead for the start of a string or a comma followed by whitespace, but don't include it in the match. All matches must have this in front of them.
.+? - Grab all characters, but don't be greedy.
(?=(,|$)) - Look behind for the end of string or a comma. All matches must have this behind them.
When ran on your test case of Friday, 26 Apr 2013, 18:30, I get 3 matches:
Friday
26 Apr 2013
18:30
Like m01's answer, you could try this approach with C#:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Globalization;
namespace TestDate
{
class Program
{
static void Main(string[] args)
{
string dateString = "Friday, 26 Apr 2013, 18:30"; // Modified from MSDN
string format = "dddd, dd MMM yyyy, HH:mm";
DateTime dateTime = DateTime.ParseExact(dateString, format, CultureInfo.InvariantCulture);
Console.WriteLine(dateTime);
Console.Read();
}
}
}
This will print out the localized date and time that is configured on the user's machine. For me it printed out 4/16/2013 6:30:00 PM.