Why is my formula returning a number instead of a date? - date

When trying to add days to a date in another column the value returns as a number, not a date.
I have tried to set the column format as the date for both columns B and C. I also tried using the DATEVALUE() function, but I don't think I used it properly.
=ARRAYFORMULA(IF(ROW(B:B)=1,"Second Notification",IF(LEN(B:B), B:B+1,)))
I want the value in column C to return as a date.

use this with TEXT formula:
={"Second Notification";
ARRAYFORMULA(IF(LEN(B2:B), TEXT(B2:B+1, "MM/dd/yyyy hh:mm:ss"), ))}

Related

Unsure of date format 1200819 but need to convert to 08-19-20

The column is a nvachar(20).
select [shipment_posted_date_arch]
FROM [RxIntegrity].[dbo].[DiscrepancyReport_Receipts]
When I pull this, the date is in this format of 1200819 for that column. I need to convert to normal date.
This seemed to work:
cast(convert(nvarchar(20), (19000000 + CONVERT(int, shipment_posted_date_arch))) as date)

Totaling multiple lines into once cell with different date formats

I want to search through a column of dates in the format YYYY-MM-DD (column G - in a random order) and sum up all corresponding cost values for all dates in the same month.
So, for example, the total cost for December 2019 would be 200.
My current formula is:
=SUMPRODUCT((MONTH(G2:G6)=12)*(YEAR(G2:G6)=2019)*(H2:H6))
This gives me the total cost for that month correctly, but I cannot work out how to do this without hardcoding the year and month!
How would I do this with a formula (given the two date columns are a different format)?
You can do this easily combining SUMIFS with EDATE:
SUMIFS function
EDATE function
The formula I've used in cell B2 is:
=SUMIFS($F$2:$F$6;$E$2:$E$6;">="&A2;$E$2:$E$6;"<="&(EDATE(A2;1)-1))
For this formula to work, in column A must be first day of each month!. In cell A2 the value is 01/11/2019, but applied a format of mmmm yyyy to see it like that (and chart will do the same).
paste in D2 cell:
=ARRAYFORMULA(QUERY({EOMONTH(G2:G, -1)+1, H2:H},
"select Col1,sum(Col2)
where Col1 is not null
and not Col1 = date '1900-01-01'
group by Col1
label sum(Col2)''
format Col1 'mmm yyyy'", 0))

Convert milisecond to date to compare to today's date

I have a set of data stored in neo4j in milliseconds.
I'm trying to get the data then change it to date format and compare it to today's date in where clause to get Media posts for today only.
I have tried with these
MATCH (media:Media)
RETURN date(datetime({millisecond:media.dateCreated}))
and it returns
Neo.ClientError.Statement.ArgumentError: year must be specified
next, I've tried
MATCH (media:Media)
RETURN apoc.date.field(media.dateCreated)
and it returns
Neo.ClientError.Statement.SyntaxError: Unknown function
'apoc.date.field' (line 2, column 28 (offset: 45)) "MATCH
(media:Media) RETURN apoc.date.field(media.dateCreated)" ^
I have tried multiple ways that more or less return the same kind of error
I expect the data to be shown in date format instead of milliseconds.
You can use epochMillis to create the date from milliseconds.
MATCH (media:Media)
RETURN date(datetime({epochMillis:media.dateCreated}))
This returns the date in the format as shown in the following screenshot:
This query:
RETURN datetime({epochMillis: 1475292465000});
returns the datetime that corresponds to the epoch timestamp 1475292465000:
╒════════════════════════════════════════╕
│"datetime({epochMillis: 1475292465000})"│
╞════════════════════════════════════════╡
│"2016-10-01T03:27:45Z" │
└────────────────────────────────────────┘
If you actually want a date, you can use this query:
RETURN date(datetime({epochMillis: 1475292465000}));

Comparing date value with YEAR in Tableau

I've a calculated field in Tableau which has the Years (Date Value) from a date field. When I compare this calculated field with year of another field, I get error.
IF calculated_Field = YEAR(order_date)
...
1) calculated_Field is the one created using Date value of another field.
2) Order_date is a datetime field.
Error I see in the above IF statement says "Cant compare YEAR and INT values".
When I solved that using below statement, it does not work as expected as IF returns FALSE.
IF INT(calculated_Field) = YEAR(order_date)
Ensure the comparisons are both from YEAR()
IF YEAR(another_field) = YEAR(order_date)
calculated_Field is created using Date value of another_field.
Order_date is a datetime field.

DB2 For i: Convert Char YYMMDD to Date

I have a CHAR_Date column containing date values in the format 'YYMMDD'.
I would like to do date arithmetic so I need to convert it into a Date data type. The problem is that the Char_Date also contains Blanks.
How do I cast the CHAR_Date to a DATE_Date column, with valid values?
SELECT
case when CHAR_Date = '' then TIMESTAMP('0001-01-01')
else TIMESTAMP_FORMAT(CHAR_Date, 'YYMMDD')
end
as DATE_Date
FROM TABLE_Data
You can use the function TIMESTAMP_FORMAT
TIMESTAMP_FORMAT('990205' , 'YYMMDD')
And if you want a date:
DATE(TIMESTAMP_FORMAT('990205' , 'YYMMDD'))