Excel remove timestamp from date and subtract days - excel

So I have a column say Date1 which has date in datetime stamp. I want to subtract 10 days from Date1 column and keep in another column say Date2. I only want to subtract ten days from date not from datetime.
How to remove the time stamp. Read many solutions online but could not find for excel
Input table
Date1
26-03-2000 21:00:00
25-04-2000 00:00:00
21-03-2000 01:00:00
31-03-2000 13:00:00
05-03-2012 12:00:00
Expected output
Date1 Date2 Date1_no_timestamp
26-03-2000 21:00:00 16-03-2000 26-03-2000
25-04-2000 00:00:00 15-04-2000 25-04-2000
21-03-2000 01:00:00 11-03-2000 21-03-2000
31-03-2000 13:00:00 21-03-2000 31-03-2000
05-03-2012 12:00:00 24-02-2012 05-03-2012 and so on

You could use the TEXT() function.
=TEXT(B2, "DD-MM-YYYY")
Alternatively, as the above solution could cause issue based on timezone formatting, you could remove anything past the first space:
=LEFT(B2, FIND(" ",A2,1)-1)
Place either the following in C2 (assuming those headers exist) and drag down.

You could use:
Method 1:
Date1_no_timestamp:
=TEXT(A2,"dd-mm-yyyy")
Date2:
=TEXT(A2-10,"dd-mm-yyyy")
Method 2
Date1_no_timestamp:
=RIGHT("0"&DAY(A2),2)&"-"&RIGHT("0"&MONTH(A2),2) & "-" & YEAR(A2)
Date2:
=TEXT(DATEVALUE(E2)-10,"dd-mm-yyyy")
Results:

You can also use the INT() and TRUNC() functions:
=INT(A2)
=TRUNC(A2)
Their behavior is identical for positive numbers - the decimal part is sliced off.

Related

Converting integer to time format in excel

Date
19112018
19112016
19112015
19112013
I have a column named Date.
I want to convert 19112018 to 2019-11-20 18:00
19 means year 2019
11 month
20 days
18 is hour
Thanks .
Use the following formula:
=DATE(20&LEFT(A2,2),MID(A2,3,2),MID(A2,5,2))+RIGHT(A2,2)/24
Or:
=--(20&REPLACE(REPLACE(REPLACE(A2,7,0," "),5,0,"-"),3,0,"-")&":00")
Then format the output cell:
yyyy-mm-dd hh:mm

Power Query - Create date from datenumber and time column

In Excel's powerquery editor I have two columns. One is a daynumber (1 to 365) and the other is the time. I would like to merge the two columns to a datetime column. Day 1 will correspond with 01-01-2000. How can I do this?
For example:
column 1: 365,
column 2: 02:00:00
Transform column 3: 31-12-2000 02:00:00.
You can use this to add a column which combines the relative date and time values:
= Table.AddColumn(#"Changed Type", "DateTime", each DateTime.FromText(Date.ToText(Date.AddDays(#date(1999,12,31),[#".1"])) & " " & Time.ToText([#".2"], "hh:mm:ss")), type datetime)
Check your logic for the date of Day 0, though - if day 1 is 01/01/2000 then day 365 <> 31/12/2000...
Excel dates are built up on float values where the integer is the number of days passed since 1900-01-01 and the fraction is the time of day.
With that in mind 2000-01-01 is 36526.
With the formula:
=36526+A1+B1
You get the datetime value, then just set the prefered cell format
With this formula 365 + 02:00:00 will become as you expect in question.
But 1 can't be 2000-01-01 then, it has to be 2000-01-02. Or you need to specify where to remove a day becasuse the math does not add up.

Time Length Of Subset

I am using Excel 2010, and have access to PowerPivot.
I am trying to find out how to work out the time each subset lasted.
Here is an example of the data:
Run: Date: Time:
A 31/01/2018 20:00:00
A 31/01/2018 21:00:00
A 31/01/2018 22:00:00
A 31/01/2018 23:00:00
A 01/02/2018 00:00:00
A 01/02/2018 01:00:00
B 04/02/2018 10:00:00
B 04/02/2018 11:00:00
etc.
I want to find out the length of time between the first row and the last row in each different subset, so that the output will be:
Run: Time Taken:
A 05:00:00
B 01:00:00
TIA,
Teuthis
I've managed to answer the question myself, for anyone who has the same issue. Here is a picture of the solved spreadsheet, with the formula in red.
Spreadsheet inc solution
The formula is:
=(LOOKUP(A15,$A$2:$A$9,($B$2:$B$9+$C$2:$C$9)))-((INDEX($B$2:$B$9,MATCH(A15,$A$2:$A$9,0)))+INDEX($C$2:$C$9,MATCH(A15,$A$2:$A$9,0)))
=(LOOKUP(search term,array to search,(date to search in+time to search in)))-((INDEX(date to search in,MATCH(search term,array to search,0)))+INDEX(time to search in,MATCH(search term,array to search,0)))
NOTE:
You will need to make sure that the times are all in hh:mm and not dd/mm/yy hh:mm, otherwise the ones close to midnight will be incorrect.

How to add a column with the corresponding day?

I want to create data that ranges from 01/01/2004 00:30:00 to 31/12/2004 23:30:00 with time step half hourly. I would like also to add a column with just the corresponding day using excel for example:
01/01/2004 00:30:00 1
01/01/2004 01:00:00 1
01/02/2004 00:30:00 2
31/12/2004 23:30:00 365
I tried to make it but I wonder why from cretin date the time step was changing from:
03/01/2004 **01:30**
03/01/2004 **02:00**
to
03/01/2004 **02:29**
03/01/2004 **02:59**
03/01/2004 03:29
03/01/2004 03:59
Any help?
Assuming your date is in cell A1, the following formula will work:
=INT(A1)-DATE(YEAR(A1),1,0)
The Int removes the time from the date, and then it subtracts December 31st of the previous year to produce the number of days that have passed in the year.
For the step, use formula
=A1+1/48 and copy down.

Excel - Date Range includes given time of day (a better approach)

Given a set of DateTime ranges in excel, such as:
Start Finish
13/03/2012 10:00:00 14/03/2012 03:00:00
15/03/2012 08:30:00 15/03/2012 10:00:00
And some TimeSpan such as:
Start Finish
07:00:00 09:00:00
How would you determine if the time span falls in some given date range?
An approach like this might be a start:
AND(B2 < DATEVALUE(TEXT(B2, "dd/mm/yyyy")) + TIMEVALUE("07:00:00"),
B3 >= DATEVALUE(TEXT(B3, "dd/mm/yyyy")) + TIMEVALUE("09:00:00"))
Though it relies on the being able to provide the start/finish values explicitly as opposed to two dates in any order. A conditional on start <= finish would do, but seems like it's overly complicated.
Is there a better way?
Edit: Bonus points for a simple approach to finding the percentage of the date range that falls in the time span
Seems like you're assuming that the dates will always be the same day, is that the case?
Try
=AND(MOD(A2,1)<=F2,MOD(B2,1)>=G2)
For percentage
=MAX(0,MIN(MOD(B2,1),G2)-MAX(MOD(A2,1),F2))/(B2-A2)
Update:
If the date range can be unlimited, 1 day or many, then you can use this formula to get the total hours within the timespan
=(INT(B2)-INT(A2))*(G$2-F$2)+MEDIAN(F$2,G$2,MOD(B2,1))-MEDIAN(MOD(A2,1),G$2,F$2)
that assumes that the timespan doesn't cross midnight - if timespan may cross midnight, e.g. could be 08:00 - 11:00 but could also be 22:00 - 03:00 then this formula should work
=(F$2>G$2)*(B2-A2)+SIGN(G$2-F$2)*((INT(B2)-INT(A2))*ABS(G$2-F$2)+MEDIAN(F$2,G$2,MOD(B2,1))-MEDIAN(MOD(A2,1),G$2,F$2))
This should give the number of hours falling in the time span (but it's definitely not simple!):
=MEDIAN(F2,G2+(G2<F2),MOD(B2,1)+(MOD(B2,1)<MOD(A2,1)))
-MEDIAN(F2,G2+(G2<F2),MOD(A2,1))
+(F2<G2)*(MOD(B2,1)<MOD(A2,1))*MAX(MIN(MOD(B2,1),G2)-F2,0)
If this is greater than 0, the date range falls in the time span, divide this by B2-A2 for the percentage.
e.g. Date Range: 6:00PM - 9:00AM, Time span: 7:00AM - 7:00PM returns 03:00 which is 20% of the date range.
Say the date ranges are in columns A and B, and the Timespan in F2 and G2.
Apply the following formulas and drag down.
H2 = IF(AND($F$2>=RIGHT(A2,8),$F$2<RIGHT(B2,8),$G$2>RIGHT(A2,8),$G$2<=RIGHT(B2,8)),1,0)
Column H gives tells you if it's true for a particular date range.
I1 = SUM(H2:H4)/COUNT(H2:H4)
I1 gives you the percentage

Resources