Converting a date/math formula in Excel into Numbers for Mac - iwork

I have a formula in Excel that subtracts a birth date from today's date and divides by 365 which gives the age in decimal format. Example below.
B4 is equal to birthday of 10/03/2011.
E4 is today's date.
The result is 2.73. My child is a little over 2 and 1/2.
=IF(B4>0,(E$4-B4)/365," ")
When I try to use this formula in Numbers for Mac, it gives me an error about comparing dates with numbers and so. I looked at DatedIF, TimeValue, and DateValue but couldn't figure out how to do it in Number.
Anyone know how I could get this formula to return a decimal value of 2.73 years of age?

Assuming B4 is in "date" format, you could try the following formula
=IF(ISBLANK(B4),"",YEARFRAC(B4,TODAY(),1))
Here is some documentation on YEARFRAC from the horse's mouth
Try entering the formula
=B4>0
in a different cell, you will then encounter en error
You can’t compare a date with a number because their data types are different.

Related

Google SHEET - Timestamp being interpreted as text - How to convert

I've a dataset in which the timestamp is in this format 03.01.2019 7:49 and the system interpret it as text.
Is there a formula to convert it to date so to divide the dataset by months (MONTH obviously is giving error in this format)
Trying to pivot the dataset by months

MATLAB: Find all values on one date, then filter down to an hour and find average [duplicate]

This question already has answers here:
Counting values by day/hour with timeseries in MATLAB
(3 answers)
Closed 6 years ago.
I have a year's worth of data, the data is recorded one minute intervals each day of the year.
The date and time was imported from excel (in form 243.981944, then by adding 42004 (so will be for 2015) and formatting to date it becomes 31.8.15 23:34:00).
Importing to MATLAB it becomes
'31/08/2015 23:34:00'
I require the data for each day of the year to be at hourly intervals, so I need to sum the data recorded in each hour and divide that by the number of data recorded for that hour, giving me the hourly average.
For some reason the data in August actually increments in 2 minute intervals, data for every other month increments in one minute intervals.
ie
...
31/07/2015 23:57:00
31/07/2015 23:58:00
31/07/2015 23:59:00
31/08/2015 00:00:00
31/08/2015 00:02:00
31/08/2015 00:04:00
...
I'm not sure how I can find all the values for a specific date and hour in order to work out the averages. I was thinking of using a for loop to find the values on each day, but when I got down to writing code realised this wouldn't work the way I was thinking.
I presume there must be some kind of functions available that would allow for data to be filtered by the date and time?
edit:
So I tried the following but I get these errors.
dates is a 520000x1 cell array containing the dates form = formatIn.
formatIn = 'DD/MM/YYYY HH:MM:SS';
[~,M,D,H] = datevec(dates, formatIn);
Error using cnv2icudf (line 131) Unrecognized minute format.
Format string: DD/MM/YYYY HH:MM:SS.
Error in datevec (line 112) icu_dtformat = cnv2icudf(varargin{isdateformat});`
Assuming your data is in a matrix or cell-array of strings called A, and your other data is in a vector X. Let's say all the data is in the same year (so we can ignore years)
[~,M,D,H] = datevec(A, 'dd/mm/yyyy HH:MM:SS');
mean_A = accumarray([M, D, H+1], X, [], #mean);
Then data from February will be in
mean_A(2,:,:)
To look at the data, you may find the squeeze() function useful, e.g.
squeeze(mean_A(2,1:10,13:24))
shows the average for the hours after midday (by column) for the first ten days (by row) of February.
See also:
Counting values by day/hour with timeseries in MATLAB

d3 date/time plotting out by 100 years

Can anyone help a beginner d3'er? I've created a scatter plot using d3 that shows Filing Date (of a Document Family) on the x-axis, and # family Members on the y-axis. Dots are all the same radius and are colour coded by Status. I have 300+ data records in a csv file format and all but the first 4 of them plot perfectly. All dates are post 1900.
Included below are the first 9 lines of the csv data set.(I've used line breaks here to make it a bit more readable). The first 4 records are plotting out at +100 years on their actual date. e.g. 1934 plots as 2034.... but the 3-Nov-75 and the ~300 others all plot as expected. The data came from an Excel spreadsheet, all date cells were formatted the same way, all show the correct 4-digit date year, and none behave as text strings instead of dates. The date display format in Excel was dd-mmm-yy.
Num,Word,FilingDate,Status,Type,FamNum
63872,Word1,23-May-34,Removed,Word,2
69105,Word2,19-Oct-36,Registered,Word,1
175164,Word3,31-Jul-62,Registered,Word,6
207804,Word4,1-Feb-67,Registered,Word,6
291765,Word5,3-Nov-75,Registered,Word,12
381067,Word6,15-Sep-82,Removed,Word,2
381069,Word7,15-Sep-82,Removed,Word,2
402936,Word8,27-Jan-84,Removed,Word,2
410476,Word9,20-Jun-84,Removed,Word,2
I've included the following in the html code, which is working for all but the first 4 records.
// Parse the date/time
var parseDate = d3.time.format("%d-%b-%y").parse;
Does anyone have any suggestions on what may be going haywire?
Thanks.
You will have to hack a little to produce the date you wish.
Instead of using
var parseDate = d3.time.format("%d-%b-%y").parse;
create a new function to parse your date:
var parseDate = function(d){
var last2 = parseInt(d.slice(-2));
var date = d3.time.format("%d-%b-%y").parse(d)
if(last2 < 69){//if year is less than 69 then change the year
date.setFullYear(1900 + last2);//will generate 1900 date
}
return date
}

Convert Excel date from date serial number to Hijri date

I have a large report data, 30k+ rows in Excel, their are two values which have dates, the dates are in Hijri, 80% of the dates is correct, but a few values appear in date serial number, which is 40383 instead of 1432/8/12, is there any way to convert those back to date, with this format, (yyyy/mm/dd) because I have written another function to calculate dates, and overlapping values, ...
Selection.NumberFormat = "[$-1170000]B2yyyy/mm/dd;#"

datetime format in matlab

I have some data that was given to me in excel and the time format is rather confusing. The fist column of the is the DateTime but with incorrect HH:MM and the second column is the correct hour of the day HH:MM:
time = {'01/01/2000 00:00',num2str(2300);
'01/01/2000 00:00',num2str(2400);
'01/01/2000 00:00',num2str(10);
'01/01/2000 00:00',num2str(100)};
However, when the time exceeds midnight, instead of being 00:10 the time is 10, and 01:00 is 100. How could I alter these to the correct format? i.e. from the example above I would like the outcome to be:
time = {'01/01/2000 23:00';
'01/01/2000 24:00';
'01/01/2000 00:10';
'01/01/2000 01:00'};
How could I achieve this?
Using sprintf in MATLAB, you can use the field width specifier:
where
Field width:
Minimum number of characters to print. Can be a number, or an asterisk (*) to refer to an argument in the input list. For example, the input list ('%12d', intmax) is equivalent to ('%*d', 12, intmax).
Thus your times should end up all looking like "XX:XX", with the leading zero added by the sprintf if it is missing and the colon added in.
Thanks to #Junuxx for the exact command: sprintf('%02i:%02i', hours, minutes)
To separate hours and minutes, you would obviously do time % 100 to get the minutes and integer divide by 100 to get the hours.
From there, you simply strcat or concatenate ["a" "b"] your two columns to get your desired result.