Excel: Check cell for date

2019-02-19 17:11发布

Short story short:

I want to check the cell C21 if it contains a date. I can't use VB cause it's deactivated by GPO.

Used this from this page

D21 contains this:

=WENN(ISTZAHL(DATWERT(C21));"date";"no date")
in english
=IF(ISNUMBER(DATEVALUE(C21))...

C21 this:

=HEUTE() # in english: =TODAY() Maybe other dates later, but allways in the correct format

but it allways returns "no date"

4条回答
够拽才男人
2楼-- · 2019-02-19 17:30

Use this formula, the expression will return TRUE if cell A1 contains an invalid date.

=ISERROR(DATE(DAY(A1),MONTH(A1),YEAR(A1)))

This formula works by evaluating each component part of the date: DAY, MONTH and YEAR and then aggregating them using the DATE function.

ISERROR will the catch any errors by returning TRUE (invalid) otherwise FALSE (valid).

Obviously the date value in cell (A1) must contain values >= 01/01/1900.

Useful for "Conditional Formatting".

查看更多
女痞
3楼-- · 2019-02-19 17:32

use the following formula ...

=IF(NOT(ISERROR(DATEVALUE(TEXT(C21,"mm/dd/yyyy")))),"valid date","invalid date")

I think it will solve your problem.

查看更多
Viruses.
4楼-- · 2019-02-19 17:37

Use this: =IF(LEFT(CELL("format",C21))="D",..,..). Learn more about CELL formula here.

In your example =TODAY() already a real date and not a date stored as text, so doesn't make too much sense to use DATEVALUE there.

Update

Here are some example dates and how CELL recognize them:

format          value           output
dd/mmmm/yyyy    12/June/2015    D1
dd/mm/yyyy      12/06/2015      D1
yyyy            2015            G
general         2015            G
dd/mm           12/06           D2
mmmm            June            G
dd mmmm yyyy    12 June 2015    G

Note: CELL is not volatile, so if the format of source cell is changed it won't be refreshed automatically, you need to either recalculate your sheet / book, either open the formula and press enter (also automatice recalculation initiated by any other volatile formula will cause it to refresh).

查看更多
来,给爷笑一个
5楼-- · 2019-02-19 17:37

Excel stores dates as numbers. 1 is 1-Jan-1900.

When it comes to numbers in a cell, Excel cannot tell if a number is meant to be a number or a date.

Today is 11/06/2015 as a date and 42166 as a number. For the consumer of a spreadsheet, the cell can be formatted to display the number as any number format or as a date. Excel formulas cannot tell whether the number in that cell is "meant" to be a date.

So, there is no Excel formula that you can use in a spreadsheet that will tell you if cell A1 is about 42166 widgets or if contains the date of June-11-2015.

查看更多
登录 后发表回答