I just found out that Excel 2013 has a DAYS() worksheet function. It appears to function exactly the same as subtracting one date from another.
One of the blogs I visited said that DAYS() permits you to work with text strings as dates, but I found that text strings also work with subtraction, as in:
="7/15/2016"-"7/1/2016"
which results in 14 when I enter it, which is the same result as
=DAYS("7/15/2016","7/1/2016")
Does anyone know what DAYS() will do that date subtraction will not?
Thanks!
Days can be more dynamic for example you could create a more complex formula with dynamic variables like this =DAYS(VLOOKUP(C3,C5:E16,3,FALSE),B3). In the example you sent it is more common for them to be static. Using the cells themselves can provide a similar function assuming they are in the same date and number formats. So an example using the same formula as above would be =VLOOKUP(C3,C5:E16,3,FALSE)-B3.
I have cells in my excel sheet that contain a date.
The display format for these cells is a custom format "mmmmm-yy"
so that the date "7/1/16" appears as "S-16". This works format works on the excel sheet, however, in VBA I try to call the Format() function on these cells, it does not yield the same format.
Format( <Date_Cell> , "mmmmm-yy")
Gives
"April4-16"
on the chart, for example.
Why does the Format function not behave the same as formatting a date cell?
Edit: According to the office support website, Format a date the way you want, I am using the correct format, but it is not producing the result the website claims it should.
Edit2: Turns out cell date formatting works differently than the VBA Format function, as the selected answer points out.
The meaning of the format symbols of the VBA function Format and the Excel Date Format are not 100% identically.
You could use the worksheet function TEXT like:
Application.Text( <Date_Cell> , "mmmmm-yy")
to achieve what you want.
The VBA Format function doesn't support the "mmmmm" format as first letter of the month (see the documentation for supported formats). Your output is actually parsing as "mmmm" (month name), then "m" (month number). If you only need the first letter of the month, you'll need to parse it out manually:
Left$(MonthName(Month(<Date_Cell>)), 1) & "-" & Right$(CStr(Year(<Date_Cell>)), 2)
One more option:
Change the number format of the cell:
Range("A1").NumberFormat = "mmmmm-yy"
My data is extracted from an application and it has a text that looks like a date/time in excel. How do I actually convert "3/24/2016 11:22:07 PM" (in text) to a real date/time conversion? I've tried formatting the cells but it doesn't work.
For a date conversion:
=DATEVALUE(TEXT(A1,"MM/DD/YYYY"))
For a time conversion:
=TIMEVALUE(TEXT(A1,"HH:MM:SS"))
For datetime conversion:
=DATEVALUE(TEXT(A1,"MM/DD/YYYY"))+TIMEVALUE(TEXT(A1,"HH:MM:SS"))
Where A1 has the data you wish to convert.
By the way, then you may wish to format the cell to a date/time or whatever.
Hope that helps.
1) try using the DATEVALUE function and see if that works for you.
2) A more reliable way, since datevalue does not always work is to strip the text out manually and insert it into and excel date value. You are going to want to use a combination of the following functions:
DATE
TIME
IF
FIND
MID
LEFT
RIGHT
LEN
Now in my opinion the easiest way to do this is to work with multiple helper columns to build out all the steps. One column per step. When you get your final answer, you can substitute or copy paste your formulas from the helper columns into the final formula until you are left with one variable. The reason I say this is that the final formula referring to only 1 variable gets rather lengthy/ugly and very hard to trouble shoot if you make a typo, forget a bracket or something goes wrong. When I did this approach I used a totally of 14 columns (includes final formula). When I packed it all up into 1 formula it resulted in this:
DATE(RIGHT(LEFT(A3,FIND(" ",A3)-1),4),LEFT(LEFT(A3,FIND(" ",A3)-1),FIND("/",LEFT(A3,FIND(" ",A3)-1))-1),MID(LEFT(A3,FIND(" ",A3)-1),FIND("/",LEFT(A3,FIND(" ",A3)-1))+1,FIND("/",LEFT(A3,FIND(" ",A3)-1),FIND("/",LEFT(A3,FIND(" ",A3)-1))+1)-FIND("/",LEFT(A3,FIND(" ",A3)-1))-1))+TIME(LEFT(RIGHT(A3,LEN(A3)-FIND(" ",A3)),FIND(":",RIGHT(A3,LEN(A3)-FIND(" ",A3)))-1)+IF(AND(LEFT(RIGHT(A3,LEN(A3)-FIND(" ",A3)),FIND(":",RIGHT(A3,LEN(A3)-FIND(" ",A3)))-1)<12,RIGHT(RIGHT(A3,LEN(A3)-FIND(" ",A3)),2)="AM"),0,12),MID(RIGHT(A3,LEN(A3)-FIND(" ",A3)),FIND(":",RIGHT(A3,LEN(A3)-FIND(" ",A3)))+1,FIND(":",RIGHT(A3,LEN(A3)-FIND(" ",A3)),FIND(":",RIGHT(A3,LEN(A3)-FIND(" ",A3)))+1)-FIND(":",RIGHT(A3,LEN(A3)-FIND(" ",A3)))-1),MID(RIGHT(A3,LEN(A3)-FIND(" ",A3)),FIND(":",RIGHT(A3,LEN(A3)-FIND(" ",A3)),FIND(":",RIGHT(A3,LEN(A3)-FIND(" ",A3)))+1)+1,2))
Note it is set up using cell A3 as the one with the time as text that needs formatting.
3) You should also be able to use excel's text to column function located on the DATA ribbon about half way across.
4) And of course there will be a way to code it through VBA as an option as well.
=DATEVALUE(A1)+TIMEVALUE(A1) seems to work as well, since each function only returns the value corresponding to what it recognizes in the string. That is, DATEVALUE() ignores the time component, while TIMEVALUE() ignores the date component.
I am using a formula to create a series of insert statements to use in SQL. However, when I do this, dates that are part of the spreadsheet (which are formatted dd-mmm-yy and needs to be like this) are changed to numbers when I use a formula. Sorry, tried to explain this the best I could, anyone know a way around this?
My formula is below
="INSERT INTO trip VALUES ("&N1&", '"&O1&"', '"&P1&"', '"&Q1&"', '"&R1&"');"
And an example of what I will get back is
INSERT INTO trip VALUES (72952, '40911','40919', 'BD08AOG', '0080919');
40911 should read 03-Jan-12 and 40919 should read 11-Jan-12.
Format the dates using this:
="INSERT INTO trip VALUES ("&TEXT(N1,"dd-mmm-yy")...
TEXT(N1,"dd-mmm-yy") will apply your format.
Looking to convert the following 2015-10-07T23:59:59 into something that Excel actually recognizes as a date so I can then graph/chart with this data... I tried using datevalue and custom formatting but can't get the syntax quite right.
To get datetime from your string, you only need to replace T with space, convert to numeric and apply appropriate cell format.:
=1*SUBSTITUTE(A1,"T"," ")
I dont know if Excel can understand that type of format date, you should try to write your own custom function to get it in the format that you want.
How about yyyy-mm-ddThh:mm:ss for the custom format?
If the timestamp isn't needed, use =DATEVALUE(LEFT(A1,10)). If it is needed, then use =DATEVALUE(LEFT(A1,10))+TIMEVALUE(RIGHT(A1,8)). (Where cell A1 contains the datetime string you are trying to parse).
This will return the Julian date value (E.g. 42284 for the day, 42284.96 for day & time) which you can then apply Excel's built in date formatting to, it will also work for charts and pivot table grouping.