Column 1 : I have this date-time format in one column = 2018-10-08T04:30:23Z
Column 3 : I extracted date with formula = =LEFT(A11,10) and changed column format to date.
Column 32 : today(). Just to make sure both date columns match
Now when I want to compare both dates
Column 4 : =IF(C11=D11,TRUE(),FALSE())
It does not work. What did I do wrong?
One option using formulas only would be to use Excel's DATE function, which takes three parameters:
=DATE(YEAR, MONTH, DAY)
Use the following formula to extract a date from your timestamp:
=DATE(LEFT(A1,4), MID(A1,6,2), MID(A1,9,2))
This assumes that the timestamp is in cell A1, with the format in your question. Now, comparing this date value against TODAY() should work, if the original timestamp were also from today.
Should be worth trying:
=1*LEFT(A1,10)=TODAY()
May depend upon your configuration. Without format conversion (the 1*) you are trying to compare text (all string functions return Text) with a Number.
Related
I have a spark data frame having two columns (SEQ - Integer, MAIN_DATE - Date) as:
Now I want to add a column based on the condition that if the format of MAIN_DATE is "MMM-YYYY" then it should be converted to Last day of the month and new data frame should look like this:
Any suggestion will be much appreciated.
You can use Spark's when/otherwise methods in order to operate differently for each different date format of the MAIN_DATE column.
More specifically, you can simply match the MMM-yyyy date format values of the column based on the field's String length (since we know that those values we always have 8 characters) as a condition in when and then:
use to_date to convert the String value to a valid date based on a format we give as an argument, and
use last_date to get the last day of the month each curry date in MAIN_DATE is referring to.
As for the "regular" rows with the dd-MMM-yyyy date format, just a to_date conversion would be sufficient within the otherwise method.
After that, all there's left to do is to convert the dates back to the desired dd-MMM-yyyy format (because to_date converts a given date to the yyyy-MM-dd format).
This is the solution in Scala (split in into two withColumns to make it more readable, instead of an one-liner):
df.withColumn("END_DATE",
when(length(col("MAIN_DATE")).equalTo(8), last_day(to_date(col("MAIN_DATE"), "MMM-yyyy")))
.otherwise(to_date(col("MAIN_DATE"), "dd-MMM-yyyy")))
.withColumn("END_DATE", date_format(col("END_DATE"), "dd-MMM-yyyy"))
This is what the resulting df DataFrame will look like:
+---+-----------+-----------+
|SEQ| MAIN_DATE| END_DATE|
+---+-----------+-----------+
| 1|16-JAN-2020|16-Jan-2020|
| 2| FEB-2017|28-Feb-2017|
+---+-----------+-----------+
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.
I have a table with a column called that contains text. Most of the values are years. However, some have the value "present" to represent groups that are still currently active. I want to convert those values to today's year, and convert the column type to date (specifically year type). I want to avoid creating a new column if possible.
Please see below for the DAX language that worked.
= Table.ReplaceValue(#"Extracted Year2",null,DateTime.LocalNow() ,Replacer.ReplaceValue,{"Disbanded"})
I am trying to extract a month from a date in SAS, but so far all my new month variables are coming up as missing.
I have attempted to use some combinations of the month() function in SAS, but so far it just comes up as missing. The dates are formatted as follows: 01/31/2017 (MMDDYY10.)
I have tried
month = month(end_date)
Month =catx('/',put(month(end_date),z2
I would like the Month to show up as a number (01) or a 3 letter code (JAN), currently it is just missing (.)
Thanks in advance!
For month() to return a missing value the end_date variable must be numeric and missing. If end_date were a character variable the log would show invalid numeric data.
Use the monname3. format to convert a date value to a $3. character value mon
monthname = put (end_date, monname3.);
Other alternatives are:
keep the date value unchanged and change the format, or
map the date value to the first of the month value and also format that
For example:
end_date_copy = end_date;
format end_date_copy monname3.;
end_date_month = intnx('month', end_date, 0);
format end_date_month monname3.;
What you ultimately do depends on how the mon is to be used downstream in reporting or aggregating.
I have a data set with SAS date format "01JAN1980". I want to generate a variable called "quarter" with format "1980Q1" or what ever combination of year and quarter.
Here is what I my SAS codes:
quarter=QRT(date)
format quarter yyq.
but it gives me 1960Q1 instead of 1980Q1.
Does any one know where is the problem?
Thanks very much!!!
The Quarter function returns the quarter number, i.e. 1-4. SAS interprets this as a date with a value of 1, which is equivalent to 1st January 1960, then displays that date in yyq. format. So what you actually want here is just to make a copy of the original variable, without changing the value, and apply the format: quarter = date; format quarter yyq.;.
Also, in some cases you might not even need to make a copy of the variable - you can place a format statement in the middle of most procs and it will use that format for the output of the proc.