I have the year a car was purchased in column A. For example, 2015. I'm trying to calculate the age of the vehicle comparing the year provided in column A to TODAY() in an arrayformula, like this...
={"Vehicle Age";arrayformula(if(A2:A="",,(datedif(A2:A,today(),"Y"))))}
For some reason, it gives me the number 115 as the result for every cell where a year has been specified. Any idea why? I can't seem to find an answer on this anywhere on the internets.
Thanks for your help!
You are mixing apples and oranges here, so to speak.
Internally, Google Sheets sees all full dates as a number of days from an origin point of December 31, 1899. As such, the year 2015 on its own, in a comparison with a full date will be seen as two-thousand-fifteen days since December 31, 1899 (or July 7, 1905 — which was 115 some-odd years ago, as would be the case with any relatively recent year, because they'll all be interpreted in their raw form by Sheets as a cluster of days from late June to early July of 1905).
Instead, you want to compare the years only, which will mean extracting the year from TODAY(), since A2:A are already year-only numbers:
={"Vehicle Age";arrayformula(if(A2:A="",,year(TODAY())-A2:A))}
However, since any year's car models are actually released the year before, you may want to add a year to your formula:
={"Vehicle Age";arrayformula(if(A2:A="",,year((TODAY())-A2:A)+1))}
Of course, you could also have turned your A2:A years into real dates (e.g., January 1 of each year listed) and then used datedif as well:
={"Vehicle Age";arrayformula(if(A2:A="",,datedif(DATE(A2:A,1,1),today(),"Y")))}
... or with that extra year added ...
={"Vehicle Age";arrayformula(if(A2:A="",,datedif(DATE(A2:A,1,1),today(),"Y")+1))}
={"Vehicle Age";arrayformula(if(A2:A="",,datedif(DATE(A2:A,1,1),today(),"Y")))}
Not working
This question already has answers here:
Rails formatting date
(4 answers)
Closed 4 years ago.
I have a variable containing a date in this form: (2018-03-21 18:49:49 UTC)
and I would like to display in this form: (day / month / year) but I can not find a solution. Do you have an idea ? Thank you !
Well, I guess this could work.
print "What year?"
year = gets.chomp!
print "What number month?"
month = gets.chomp!
print "What number day?"
day = gets.chomp!
puts "#{day}/#{month}/#{year}"
I'm new to ruby but I think this should work.
This question already has an answer here:
Date parsing in Go
(1 answer)
Closed 6 years ago.
I have this date, in this format:
25.04.2016
I need to parse this into a Golang time object so that I can store it in my DB.
What is the best way to do so? I can't find a standard parsing format that will do so.
To parse a date in go you provide a format string that represents the date Mon Jan 2 15:04:05 MST 2006 so in this case it would look like;
t, _ := time.Parse("02.01.2006", "25.04.2016")
(play ground example; https://play.golang.org/p/6E9zshNeFG )
Check the packages docs here; https://golang.org/pkg/time/#example_Parse
I believe the arbitrary date you use as the example format is the first day of the Go programming language.
This question already has answers here:
Number of days between two NSDates [duplicate]
(16 answers)
Relative string from NSDate
(5 answers)
Closed 8 years ago.
So I'm trying to get the amount of days a blog post was posted ago. The end result would be something like "posted X days ago."
After spending some time on the problem, I figured it out by getting the NSTimeInterval, dividing to get days and then rounding. Although I got the output I wanted, I feel I am doing it wrong or there is a much more straight forward way of doing it.
tempDate is a NSDate object of when the blog was posted.
NSTimeInterval timeSince = [tempDate timeIntervalSinceNow];
timeSince = timeSince/60/60/24*-1; // seconds to days
int daysSince = lroundf(timeSince);
you could use NSCalendar and NSDateComponent to get the number of days (and you don't even need to convert your tempDate)... See the good answer given here Number of days between two NSDates
I'm working in Google Spreadsheets trying to compare two years of data for each month.
year jan feb mar apr may etc
2012 4 3 5 6 4 3
2013 2 4 5
I want to be able to compare the data I have so far because if I don't have enough data, then the comparison will not be accurate until all of the months are complete.
How do I compare 2013's jan,feb,march to 2012's jan,feb,march and have it dynamically adjust?
For instance, if I input april, have it compare jan-april of 2012 as well.
Please try:
=IF(ISBLANK(B3),"",SUM($B3:B3)/SUM($B2:B2)-1)
in B4 and copy across to suit.
Yes, in this case the formula works (or not!) the same in Excel and Google Docs.