Split character column by date into new date column - date

I am working with a character vector describing locations and dates. I am trying to separate the vector into a location and date column. The character line does not possess clear rules for using stringer or separate functions, however, the character line always ends with a date like "April 20." I have tried separating on months of the year, but then lose the month name.
#sample
locations <- c("Molino November 28.", "Wolf River Bridge December 4.")
df <- data.frame(locations)e here
#using stringr produces error
df1[c('location', 'date')] <- str_split_fixed(df$locations, c('November', 'December'), 2)
Trying to produce vectors like below:
Location Date
"Molino" "November 28"
"Wolf River Bridge" "December 4"

Related

Apps Script: How to convert English date format to German date format?

I am pretty sure this is a small issue, but I just can´t figure out how to solve it, as I am new at using Apps script :(.
ISSUE:
I have a sheets consisting of 2 columns: A and B. The column A contains dates written in German format (Day/Month/Year). Example: October 18th, 2021 is written 18/10/2021. Now all I want to do is increment each day from column A by 1 day and write the outcome (so, the incremented days) in column B.
ATTEMPTED SOLUTION:
I´ve figured out how to increment the days and write the outcome in column B. But I am struggling to add the second part of my script, so that the incremented dates are written in German in column B (See scripts below).
QUESTION:
How and where can I include the “Utilities.formatDate()” into my code, so that the dates in column B are formatted in German? (So, DAY/MONTH/YEAR instead of MONTH/DAY/YEAR)?
Thank you so much in advance for your help.
// Increment dates in colum A by 1 day and write this incremented date in colum B
function incrementDateInGermanFormat() {
var ss = SpreadsheetApp.getActiveSheet();
var date = new Date(ss.getRange(1, 1).getValue());
ss.getRange(1, 2).setValue(new Date(date.setDate(date.getDate() + 1)));
}
// This is the line I´m having trouble to include in the script above
Utilities.formatDate(date, Session.getScriptTimeZone(), "dd/MM/yyyy")
It is bad practice to convert date to strings. In this case, a better alternative is to simply change column B's date format to german in the spreadsheet user interface or use .setNumberFormat("dd/mm/yyyy") on column B.

Converting number to date format using Power Query Editor

I need help to convert Numbers into date format using Power Query Editor in either Excel or PowerBI
The date appears in number form like this 930101 and I want to convert it to normal Uk date format
Not sure which one is month and which one is date among "0101" in your string. But you can handle this your self and follow this below steps for get your required output in Power Query Editor-
First, split your string value using fixed 2 character and your data will be divide into 3 column now. define which one is Year, Month and Day.
Now, merge those 3 column maintain the UK pattern DD/MM/YY using a separator "/" and you will get a string like "01/01/93".
Finally, create a custom column using the below code-
Date.From([Merged],"en-GB")
Here is the final output-
In the above image, you can see the date in still US format just because of my Laptop's locally setup.

How to compare dates or date against today with query on google sheets?

I'm working on making a replica of sheet1 on to another sheet2 (same document), and query() worked fine until the column i want to filter are formula cells (LONG ones each with query, match, etc).
What i want to do is filter the rows in sheet1 where the event date in column M is upcoming (there are more filter conditions but just to simplify this is the main problem).
I don't want the rows where the date is either empty, in the past (various date formats), or where the formula give a result of empty string "".
The formulas i've tried (which gives error) - note i'm just selecting 2 columns for testing:
=query(sheet1!A3:N, " select I,M where I = 'Singapore' AND DATEVALUE(M)>TODAY() ",0)
=query(sheet1!A3:N, " select I,M where I = 'Singapore' AND M>TODAY() ",0)
This formula doesn't give error but doesnt show correct data - shows all data except Jan 2017 - August 7 2017:
=FILTER(sheet1!A3:N, sheet1!I3:I="Singapore", sheet1!M3:M>TODAY())
This formula gives empty output:
=query(sheet1!A3:N, " select I,M where I = 'Singapore' AND M='22 August' ",0)
There's no today() in Query. Use now() instead:
=query(sheet1!A3:N, " select I,M where I = 'Singapore' AND M > now() ",0)
Or if you want now() without time(equivalent to TODAY()), use:
todate(now())
For this to work, provided you have all the correct dates in M in any format, which Google sheets recognises (i.e., the formula bar shows the correct date or time) regardless of the actual string. If not, You should manually convert all those remaining dates to correct format. The correct format of date to be entered in the query formula is date 'yyyy-mm-dd'. It doesn't matter what format the date is in sheets ( as long as Google sheets recognises this), but the actual formula must only contain date in this format for comparison. For example , to find all dates less than 31,August, 2017,
=query(A2:B6, "select A where A < date '2017-08-31'")
You can use this to figure out all the dates, which Google doesn't recognise: N1:
M:M*1
If you get an error in the helper column N, then those dates are not recognised. Even if you did not get error, it is possible that Google sheets mis-recognizes the date. There is also a more specific function:
=ARRAYFORMULA(ISDATE(M:M))
References:
Scalar functions

SAS: Combine YEAR and MONTH data into a single mm/dd/yyyy date without changing types

Question: How do I combine YEAR and MONTH data into a single mm/dd/yyyy date without converting from numeric to character types?
I have date data which needs to be read into SAS. It comes in two columns, YEAR and MONTH. The data looks similar to this:
YEAR MONTH
2012 1
2012 1
2013 10
2012 2
2014 7
The data must be stored in mm/dd/yyyy format. For example, YEAR = 2013 and MONTH = 10 corresponds to 10/01/2013.
I have accomplished this via:
if month = 1 then
date = input(compress("01/01/"||year),mmddyy10.);
else if month = 2 then
date = input(compress("02/01/"||year),mmddyy10.);
...
However, the log gives the following note:
NOTE: Numeric values have been converted to character values at the
places given by:
(Line):(Column).
I understand that this is being done because SAS stores dates as numeric values since January 1, 1960. The Compress function returns a character value. Thus, the numeric data is being coerced into a character type.
While the above code sufficiently solves my problem, the note implies that date formatting should not be handled in this way (via type conversion).
Use the mdy() function:
date = mdy(month, 1, year)

SAS EG date issue

i want to build a bar chart where the X-axis is month year ( example : NOV 2010)
in my dataset i got a column called MonthYear contains the month year value.
The problem is when i use the MonthYear column as the X-axis value , in the bar chart X-axis it come out numeric value (example : 14800 ...). I google out and found out that it is the date value in SAS.
i would like to know how can i display date as "NOV 2010" form on X-axis in bar chart.
i tried to change it into a character value column but it is sort alphabetically.
Add the format monyy7. on the MonthYear column of the source dataset.