Converting "January 5th" and "February 1st" to dates (removing ordinals/th/rd/st) - datetime

I have ~100 rows of live data from a website that look like this:
January 24th 12:30pm NINJA Party
January 31st 3:30pm Classic Party
How can I get Google Sheets to recognize the dates? It doesn't recognize the ordinal endings (e.g. th/st/rd).
Thank you.

This formula might work as you want (amend the A2:A range as required):
=ArrayFormula(IF(A2:A="",,(IFERROR(DATEVALUE(LEFT(A2:A,SEARCH(" ",A2:A)+2)),DATEVALUE(LEFT(A2:A,SEARCH(" ",A2:A)+1))))))

Related

how to transform Carbon date into m-d-y format? (opposite)

I've this date format: November 12, 2018 and I want to transform it into (m-d-y) format to be able to insert it into DB (as dynamic data..). Any help will be appreciated.
checked most of the answers, all are talking how to convert from (d-m-y) into Carbon (human format) .. I couldn't find something for this.
Using 'Carbon', this will return the desired date format which is: 2021-12-27
Carbon::parse('December 27, 2021')->format('Y-m-d');
note: I'm using Laravel framework.

How to get first date of the week based on week number and year in Moment.js?

I tried to get the start date of a specific week in Moment.js from the week number and year by doing moment().year(...).isoWeek(...).startOf('isoWeek')
But It seems that this function is not always returning the correct date.
For example when I live in England and a week always starts on a monday.
We should get 31 Dec 2018 when we ask for the first day of week 1, 2019.
This wasn't the case on 31 Dec 2018 as the result I received was 30 Dec 2019 as the begin date of week 1, 2019. See example
I think I found the solution I was looking for
moment()
.isoWeekYear(year)
.isoWeek(week)
.startOf('week')
Please note that, as i18n section of the docs states:
By default, Moment.js comes with English (United States) locale strings. If you need other locales, you can load them into Moment.js for later use.
So if you want to use en-gb locale you have explicitly load it (in the browser, you can use en-gb.js file or moment-with-locales.js and then set locale using moment.locale('en-gb')).
You don't have to use year() setter, because it sets the year to 2019 and moment().year(2019).isoWeek(1) gives you the first isoweek of the 2020. You can create a moment object for a given year using moment({y: year}) instead.
You have to use week() instead of isoWeek if you want locale dependent results:
Because different locales define week of year numbering differently, Moment.js added moment#week to get/set the localized week of the year.
The week of the year varies depending on which day is the first day of the week (Sunday, Monday, etc), and which week is the first week of the year.
Here a full code sample:
// Set locale to British English
moment.locale('en-gb');
var year = 2019;
var firstMonday = moment({y: year}) // get first day of the given year
.week(1) // get the first week according locale
.startOf('week'); // get the first day of the week according locale
// Show result
console.log(firstMonday.format());
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.23.0/moment-with-locales.min.js"></script>
You can use format() to display the value of a moment object.

moment tz convert string

This should be simple, but I spent hours going over documentation and still got nothing.
I have this string:
var time = "2018-09-29 23:50:21"
This time is in UTC, even though it does not say so, I know it is.
I want to convert it to PST (America/Los_Angeles) with .tz
I tried:
moment(time).tz('America/Los_Angeles').format(MomentDefaults.DateTime);
I get "Sep 29, 2018, 23:50"
I tried MANY different combination that failed in different ways.
I want to be able to print "Sep 29, 2018, 16:50" which is time in utc converted to pst.
What am I missing?
Can you change your time string to be an actual valid ISO UTC string since you are sure it is?
var time = "2018-09-29T23:50:21.000Z"
console.log(moment(time).tz('America/Los_Angeles').format()) //16:50
console.log(moment(time).tz('America/New_York').format()) //19:50
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.22.2/moment.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment-timezone/0.5.21/moment-timezone-with-data.min.js"></script>
Make sure you have the data for the timezones loaded etc as per the docs:
In Node.js, all the data is preloaded. No additional code is needed
for loading data.
When using Moment Timezone in the browser, you will need to load the
data as well as the library.

Cognos: How to show shorten dates in a cross tab in report studio?

I have this report where in cross tabs the column header shows month and year in the format of "September 2014". I want it to show "Sept 2014" instead. Can someone help me with this?
The format is actually coming from the database table so me trying to change the data format property from the properties tab hasn't done anything.
I would appreciate any help and ideas on this.
substring([Month/Year],1,4) || ' ' || substring([Month/Year],position(' ',[Month/Year]) + 1)
This will shorten the first word to 4 characters and retain the entire second word (the year in this case).

Decoding flight Arrival / Departure time format

I've been using a real time flight traffic API lately and I'm stuck at formating the arrival / departure times from a json response.
They come like this:
{
"dep_schd":1426843500,
"arr_schd":1426849800,
"departure":1426844020,
"arrival":1426849221
}
It doesn't look like anything I've seen before. Any ideas on how to make these times readable?
As a bonus, I can give you how an estimated time arrival looks like:
"eta":1426849221
Thank you
Edit:
Okay guys, with a bit more research and the help from you guys I managed to convert my date to a human readable date like this:
var departure = $('#departure');
var departureDate = new Date(json.departure * 1000);
departure.html(departureDate.toUTCString());
Now what I get is something like this:
Fri, 20 Mar 2015 09:33:40 GMT
My question is how can I make it simpler? So as I can get something like this:
Fri, 20 Mar 2015 09:33
This is Unix time. The number of seconds since 01 Jan 1970, 00:00:00 UTC.
On Unix you can use functions like localtime or gmtime and strftime to convert it to a human-readable form. Most languages have similar functions for dealing with these unix timestamps.
To display it in another format, use the "get" functions on the Date object (since it looks like this is JavaScript). For example departure.getUTCHours().
A better solution though is to use a library like moment.js to format the date easily:
var mDeparture = new moment(departureDate);
departure.html(mDeparture.format('YYYY-mm-dd'));
The format which your are displaying is called Epoch and it is then converted into human readable format.Here is a online site where u can get this in readable format http://www.epochconverter.com/
But you didn't mention in which language you want to convert , every language as methods to convert this in human readable and then you have to pick which info you want from it.

Resources