I have a column of years, 2000, 1990 > 900 (0900) > 1876 etc.... However I needed to have it in a date format e.g. 01/01/2000, 01/01/900 (01/01/0900). I can't work out how to do this. I can only see formulas which add days and months which are already in the format I would like. I only need it as 01/01 to input to QGIS as a csv file.
Dates are represented in Excel by real numbers. The integer part (to the left of the decimal place) is the number of days since 12/30/1899. The fractional part (to the right of the decimal place) is the fraction of the day. .5 = noon, .75 = 6pm, etc. How these numbers appear in the worksheet depends on the number format of the cell. So if your cell value is 36526 (or 1/1/2000) and the number format is "mm/dd/yyyy" you will see '01/01/2000' in the cell. If the number format is "mm/dd", you will see '01/01' in the cell.
I don't understand what you mean by "I only need it as 01/01 to input to QGIS as a csv file" but if you show me some code, and explain how the results you're getting differ from the results you want, I can probably help get you there.
I have 2 datetime strings in ISO 8601 format e.g. 1900-01-01 00:00:00+00:00 and 2020-03-27 23:59:59+11:00.
How can I calculate the number of seconds between these 2 datetime strings using only Excel or Excel VBA?
All the answers I come across calculates the date part only, eventhough the questions asked for timestamp.
Function TOUNIX(dt) As Long
TOUNIX = DateDiff("s", "1/1/1970", dt)
End Function
Broken down for understanding/educational purposes:
LEFT(A1,FIND("+",A1)-1)-1 - extracts the date
(VALUE(LEFT(A1,FIND("+",A1)-1)-1) - converts date to a number (-1 to account for the first second being 0)
(LEFT(MID(A1,FIND("+",A1)+1,5),2) - extract the hour from the timezone
RIGHT(MID(A1,FIND("+",A1)+1,5),2) - extracts the minutes from the timezone
/60 - 60 minutes in an hour
/24 - 24 hours in a day
IF(LEFT(RIGHT(A1,6),1)="-",1,-1) - extract the timezone modifier to determine whether the timezone adds or subtracts from value
Combined to this point, we have the number converted value of the date
* 86400 - The amount of seconds in a day
=(VALUE(LEFT(A1,FIND("+",A1)-1)-1)+((LEFT(MID(A1,FIND("+",A1)+1,5),2)+(RIGHT(MID(A1,FIND("+",A1)+1,5),2)/60))/24)*IF(LEFT(RIGHT(A1,6),1)="-",1,-1))*86400
Where you are starting with 0, you won't need to subtract from another date. If you wanted to anyway, just duplicate the formula as needed.
you will want to look at the following functions.
For text manipulations:
LEFT
RIGHT
MID
FIND
SEARCH
Concatenate or &
For date manipulation:
Datevalue
Date
Year
Month
Day
For time manipulation:
Timevalue
Time
Hour
Minute
Second
You have a couple of options. You can either strip out each individual value and place it in the appropriate date/time individual function or rearrange the date and time as a string that is identifiable by the time/date value functions.
A little background on date and time in Excel. Date are stored as an integer. 1 represented 1900/1/1, 2 represents 1900/1/2 and so on. time is stored as a decimal representing fraction of a day. 00:00 is midnight and stores as zero , 12:00 noon is stored as 0.5 to represent half the day. 24:00 is not an official Excel time, though some function will work with it. To test if a date/time is stored as text or as an excel number, you can test the value of the cell with something like ISTEXT(A1), change the formatting to general and see if the display of the cell info changes, and least reliable is to look at the justification of the information in a cell which is left aligned by default for text and right aligned by default for numbers.
Lets assume your strings are stored in A1 and A2
Because Datevalue can be a little finicky and depends a bit on system settings to determine mm vs dd I go with the method of stripping the individual components. In your case because everything has leading zeros the position of month, day, hour, minute and seconds can be hard coded instead of searching the string starting position of each based of key characters like -, :, +, and space.
Grab the year:
=LEFT(A1,4)
Grab the month:
=MID(A1,6,2)
Grab the Day:
=MID(A1,9,2)
Make the date by dropping the results into DATE as follows:
=DATE(LEFT(A1,4),MID(A1,6,2),MID(A1,9,2))
Grab the hour:
=MID(A1,12,2)
Grab the minutes:
=MID(A1,15,2)
Grab the seconds:
=MID(A1,18,2)
Make the time by dropping the results into TIME as follows:
=TIME(MID(A1,12,2),MID(A1,15,2),MID(A1,18,2))
To grab the timezone I will use TIMEVALUE to demonstrate the other method. This will convert the timezone time or decimal value instead of text like the operations above.
Grab the timezone:
=TIMEVALUE(RIGHT(A1,5)*IF(LEFT(RIGHT(A1,6))="-",-1,1)
Then you just need to combine the results together to get the whole thing in an excel date and time format:
=DATE(LEFT(A1,4),MID(A1,6,2),MID(A1,9,2))+TIME(MID(A1,12,2),MID(A1,15,2),MID(A1,18,2))-TIMEVALUE(RIGHT(A1,5))*IF(LEFT(RIGHT(A1,6))="-",-1,1)
Now that the string is converted to an excel date you need to take the difference in the cells noting that the result is days. Then you need to convert it to seconds by multiplying it by 24*60*60 = 86400.
So if you put the results in B1 and B2 then the formula for difference in seconds would be:
=(B2-B1)*24*60*60
In the example below its (F14-F12). Also note that the cells displaying time or date and time have had custom formating applied to them to dispaly 24 hour clock or date and time combined.
I am looking for a formula where I can put a 5 digit Modified Julian Date and have it convert it to today's date for me.
I did it in a way where I have a separate sheet with a table but although it works, I am looking for a way without the need of a separate table. Here is some information:
00000 should translate to 11-17-1858
58890 should translate to 02-11-2020
Every time the number goes up 1, it should go up 1 day. This needs to have leap years in consideration as well. Any help will be appreciated.
Here is a website that currently does the conversions:
http://www.csgnetwork.com/julianmodifdateconv.html
This has to be done without macros, literally need it in formula format.
Just subtract 15018 and format the result as a date.
Why 15018 and not 15020?
In Excel, 1-Jan-1900 value is 1
In your date scheme 15020 = 1-Jan-1900
But, if you had the number 15020 to convert and subtracted 15020 it would --> 0, not the desired 1.
Therefore we reduce the 15020 by 1 to 15019.
Next, there is a deliberate "bug" in Excel, widely discussed both on SO and the internet, whereby the year 1900 is erroneously classified as a leap year.
So for any date equivalent that is after 28-Feb-1900, we have to subtract an extra 1.
If you might be dealing with dates between 1/1/1900 and 2/28/1900 you will need to modify the formula to take that into account.
I'm working on an excel 2010 sheet where I mark down the date and time an event happens. The date is in one column, and auto formats to 17-Nov when I would type in 11-17 (I was fine with this). The time is in a separate column.
I am trying to find the average time an event occurred, without regard to the date, so I would use =AVERAGE(C1:C10). However, I only receive a date back (like 17-APR).
I did not format the cells before I began to enter in data, and I would simply type in a 3:27pm event as 1527, and no reformatting would happen.
Now, when I attempt to reformat the column to hhmm, all the numbers entered so far turn to 0000. When I try to edit the 0000, it is formatted as 6/13/1906 12:00:00 AM.
What I want to do is have the time formatted as hhmm and not include a date in the cell, and be able to run formulas on it, such as the average time an even occurred.
Summary:
*Currently time is entered simply as ####. I entered 3:27pm as 1527.
*Trying to reformat the time column results in 0000 in all cells in the column that previously had a ####.
*Modifying the 0000 displays as 6/13/1906 12:00:00 AM
*I want to format the time as hhmm so I can simply type in 2357, and have it display as 2357, but understand I mean 11:57pm, and let me take averages.
*Hell, even being able to enter 1547 and have it auto format to 15:47 or 3:47p would be great.
Thanks for reading my question!
An easy way to apply an autoformat (though Excel won't see it as a true "Time") is to go into Format Cells>Custom> and use ##":"##. This will turn 1245 into 12:45. Mind you, this will be a text string so if you copy it to another cell and then apply a time, it will show as 12:00:00. Excel will also not be able to run formulas on it, but it's a quick and dirty way to make it look pretty.
Another option is to have a formula such as =TIME(LEFT(A1,2),RIGHT(A1,2),) where A1 would be replaced with the cell you are actually referencing. This will convert the number to a time that Excel will recognize as a time allowing you to run other functions on it, but requires another column.
If you are entering the times as 4-digit numbers, you'll need to do a calculation to get the hours and minutes, then use the TIME function to get an actual time:-
=TIME(A1/100,MOD(A1,100),0)
Another way is
=LEFT(A1,2)/24+RIGHT(A1,2)/1440
but then you have to format the result as a time.
Excel sees a number like 1547 as approximately 4 years on from 1st January 1900 if you format it as a date, so it will come out as something like 26/3/1904 in UK format or 3/26/1904 in US-style format.
Note that the time function can only give you values up to 23:59:59 (stored as 0.999988426), but the second method will give you a datetime value with one or more days as the whole number part. This can be useful if you want to do calculations on times spanning more than one day.
The above behaviour is because dates and times are stored as real numbers with the whole number part representing days and the decimal part representing fractions of a day (i.e. times). In spite of misleading information from Microsoft here, dates actually start from 31/12/1899 (written as 0/1/1900) with serial number 0 and increment by 1 per day from then on.
Got formulas for figuring my differences between date periods in days as follows:
=IF(F7="","0",DAYS360(F6,F7)+1)
This gives the days result for each period that I am interested in, but I then need to add each period of days together and subtract them from a current date (like doing service computation). The issue is that I need to do this second calculation within a 360-day calendar as well. If I just try to do a days360() formula with one value being the current date and the other being the total number of days that I need to backtrack, then the "original" date that it comes up with is drastically off.
This seems to be the equivalent of the difference between NETWORKDAYS and WORKDAY functions. The former counts working days between two dates, the latter adds working days to a date, you essentially want the WORKDAY equivalent for DAYS360, which I don't think exists.
You can manipulate DAYS360, though, e.g. with a date in A2 and number of days to subtract (in 360 day mode) in B2 you can use this formula for the date
=A2-B2-MATCH(B2,INDEX(DAYS360(A2-B2-ROW(INDIRECT("1:"&CEILING(B2/30,1))),A2),0),0)