In excel is it possible to compare a year yyyy (say 2016) with date dd/mm/yyyy (say 01/01/2015) and find out which is greater. My assumption would be that the date in yyyy format will always be the first day of the year.
So for example
2015 v 01/01/2014 would return true
2015 v 01/01/2015 would return false
2015 v 01/01/2016 would return false
I can code this in VBA but the user needs this in a cell in an excel spreadsheet.
One option would be to write the VBA code in a function in a code module, that returns the greater value.
Public Function CompareDates(date1 AS Date, date2 As Date) As Date
'Compare date1 and date2
'CompareDates = whichever date is greater
End Function
You can then simply add the formula =CompareDates(date1, date2) in the cell
Assuming A1 = 2015 and B1 = 01/01/2015 you can try:
A1=YEAR(B1)
Do you mean something like:
=DATE(A1,1,1)>B1
Assuming your Years are in Column A and Dates are in Column B.
Related
I have 1 column that only have year value but formatted as general. I really need that value but formated as date in year only. I have tried to change the format to date, use custom to yyyy and use =year(a1) function, but it's useless. any solution?
Dates in Excel are integer values. First date Excel can recognize is 01/01/1900 which integer value is 1, number 2 would be 02/01/1900 and so on.
Number 2011 is 3rd July 1905 and because you are applying format yyyy Excel returns 1905.
You need first to do a proper date, not converting directly number 2011. So you need to type a date like 01/01/2011 (to be honest, any date from the 365 days of year 2011 would work but it is most usual to write on the first day of the year in these cases because you want just the year).
So you can do like this:
Formula in cell B1 is =DATE(A1,1,1) This will return always the first day of the year.
Now format B1 to yyyy and then it would be your expected output.
And just notice a fact: the date 01/01/2011 got an integer value of 40544 :)
I have an excel sheet with an unique id column, start date column and end date column:
ID | start date | end date
I want to count the rows (or id's) with a start date BEFORE 01-01-2020 AND and end date which is AFTER 01-01-2020 OR empty.
All dates are in dd-mm-yyyy format.
I solved it in the following way:
Added two columns named 'Start Year' and 'End Year' with the following formula:
=IF(B1;YEAR(B1);"")
With the B column the start date column and for end year it references the end date
column of course. This returns the year and if the cell is empty it returns empty.
Then I used pivot tables. Not a direct solution but it works and it is not too complicated.
I would like to change the date format of a cell with VBA, but I have no idea for that. Let take below as our example, Column A is the input and Column B is the output as it must be in Thai Calendar...
My goal is extracting the value in Column A of Sheet1 to many Sheets with the converted Date...
Here is how you can copy data from cell 'A1' to 'B1' and convert date type to Thai.
Dim mydate As Date 'create date variable
mydate = Range("A1").Value 'copy date value from Cell A1
Range("B1").Value = mydate 'paste date value into cell B1
Range("B1").NumberFormat = "[$-th-TH,107]d mmmm yyyy;#" 'convert copied format to Thai
Hope this answers your question.
sorry for that I have low rep to comment.
date change is not a code issue.
change from western date to buddadate is adding 543 yearsto western date
as excel using the number for the date.
1 equals to 1900-01-01
2 equals to 1900-01-02
43752 equals to 2019-10-14
you need to add 543 years to western date
put this on b1 cell.
=A1*1+543*365+rounddown(543/4,0)
remind that leap year comesevery 4 years so that you could adjust +rounddowns() part to correct date
I am trying to write a formula to compare a date against two dates but I need to determine the location of those two dates prior to comparison.
By way of example, I have dates in a table as below.
A B C D
1 FY QTR Start date End Date
2 2019 Q1 2/4/2018 5/5/2018
3 2019 Q2 5/6/2018 8/4/2018
4 2019 Q3 8/5/2018 11/3/2018
5 2019 Q4 11/4/2018 1/2/2019
I have the quarter I am working in cell B9. I want to determine if the date in cell H6 falls between start date and end date based on the quarter value in cell B9.
Test if H6 is >= Start date AND <= End Date
Assuming dates are entered as DateTime Serial Numbers (and formated as dates) use
=AND($H$6 >= VLOOKUP($B$9,$B$1:$D$5,2,0), $H$6 <= VLOOKUP($B$9,$B$1:$D$5,3,0))
For some reason the Excel year() formula does not return 2008 as expected!
I am using Excel 2016 (offline version)
Row C D Formula
1 SourceDate YearOnly
2 2008/12/01 1905/06/30 =YEAR(C2)
Just realized that the Year() formula returns a Number, however I had column D formatted as a Date
Changed this back to number and now I get the correct date as expected!
I also see that I can retain the Date format on column D but must then reconstruct a full date e.g. = Date(Year(C2),1,1)