I need to convert from 12 hour time to 24 hour time in excel.
I have it on this format:
11/13/2016 7:00:02 AM
I need it to be like this
11.13.2016 07:00:02
How could this be done? I have approximately 1000 cells that need to be converted.
Fully agree with Teylyn - however you may want to change the display and perhaps this is what you actually meant by "conversion". To adapt the display, let's we start with this:
Select the whole range you want to display differently and you can choose from the dropdown "More number format":
Then you can go to "Custom" on the list in the left & select something like this one:
Which gives this:
Or you can use the sample to make up a display of your own (you can edit the format line to yield anything you want).
Edit: if you like the answer, please accept it.
Dates and times are stored as numbers in Excel. How these numbers show in worksheet cells is governed by formatting. If your data contains real date/time values, you don't need to convert anything.
Use formatting to display values in a different time format in the worksheet cells. The date/time will show in the formula bar according to your computer's system settings for date/time display, but that's only in the formula bar.
Use the underlying values unchanged for calculations.
Related
I have this column in excel. The format is dd/mm/yyyy hh:mm:ss.SSS where SSS is milliseconds.
How can I make calculations such as subtracting two cells from each other? I keep getting an incorrect format error but I cannot find a format that includes date and time with milliseconds.
I am able to change the notation of the DateTime value but not split it into two cells.
Comments up above will suggest the built in test to columns method which works really well. Scotts tip about the third step is imperative. Jeroen's comments is using the DATEVALUE function which can be picky and somewhat dependent on your system settings. There is a third choice of using DATE. Jeroen's formula already does most of the work but needs a little tweaking. The nice part of DATE is it is not picky nor reliant on system settings.
Important tidbit of info. Excel stores dates as an integer with 1 representing 1900/01/01. Time is stored as a decimal which represents percentage of a day. So 0.5 is 12:00 noon. Also 24:00 is not a valid time for excel but will still work with some functions.
The DATE function looks for 3 arguments to be passed to it. Year, month, and day in that order. So it is just a matter of pulling the applicable parts of your timestamp as a string out and placing them in the right location. There is a Similar function for TIME.
Let assume one of your timestamps is located in C3
in D3 you can place the following formula to convert the date from text to an excel date:
=DATE(MID(C3,7,4),MID(C3,4,2),LEFT(C3,2))
In E3 you can place the following formula to convert the time from text to an excel time:
=TIME(MID(C3,12,2),MID(C3,15,2),MID(C4,18,6)
To get the information together its simply D3+E3. however if you want to place the whole formula in one cell and avoide helper columns, the formula would look like:
=DATE(MID(C3,7,4),MID(C3,4,2),LEFT(C3,2))+TIME(MID(C3,12,2),MID(C3,15,2),MID(C4,18,6)
Now that the time in in excel format you can perform operations on it, apply formatting to make it look like you want, and use various excel functions with it.
Currently using a calculated SharePoint column (uses same excel formulas)
I have a column "SignIn" that shows the date/time of a staff sign-in. I have another column "Late Flag" that will show if they are late or not. There are sometimes multiple sign-ins/outs throughout the day, So I need the formula to only flag them as late between a certain time frame (09:35:00 AM to 10:15:00 AM). I have tried a few different formulas - but they keep producing unexpected results (like they all show as late, when they're not).
For example:
=IF(AND([SignIn]>"9:35:00 AM",[SignIn]<"10:15:00 AM"]),"Late","")
This shows my column setup
I have a date/time column for SignIn, and a single line of text column for Late Flag
Most likely your data is converted to a timevalue and shows as "9:36:00 AM", but when selected the true cell value will be "09:36:00" which is because excel has recognised it as a time and converted it to one. However in your formula "9:35:00 AM" will be a string (text value) which will never match with a time value. To get around this you can use TIMEVALUE( in your formula to convert it like a time like so:
=IF(AND(A1>TIMEVALUE("9:35:00"),A1<TIMEVALUE("10:15:00 AM")),"Late","Not")
Also, it might be possible the time in your cell is actually text, which cannot be compared to any time value to begin with. This complicates things, but not much, just wrap a TIMEVALUE( around that as well:
=IF(AND(TIMEVALUE(A1)>TIMEVALUE("9:35:00"),TIMEVALUE(A1)<TIMEVALUE("10:15:00 AM")),"Late","Not")
Using the formula below to achieve it.
=IF(AND(TIME(HOUR([SignIn]),MINUTE([SignIn]),SECOND([SignIn])) > TIME(9,35,0),TIME(HOUR([SignIn]),MINUTE([SignIn]),SECOND([SignIn]))<TIME(10,15,0)), "Late", "")
More information: TIME function
READ CAREFULLY THE QUESTION PLEASE, IT MENTIONS EXCEL VBA.
NOT EXCEL
I was given the task of fixing a date input on a VBA form. A textbox should have the user enter the date as MM/DD/YYYY.
I am required to use an input mask, not allowed to do something as validating date after or using a calendar. So far I was able to use the 2 methods mentioned (forcing the format after using ISDATE).
However, it has now been made clear it has to be a mask so keys are filtered on entry, with the mask being visible when entering the date: __/__/____
Where you see underscore, he should only be able to enter numbers and the / are always at those positions
Is there a way to do this? I can only find a tutorial for the mask in Access VBA.
I Googled "Excel input mask" and the 2nd result was: Using an Input Mask Microsoft Excel written by Allen Wyatt...
Using an Input Mask
...You may wonder if there is a way to set up an input mask that will add the colon automatically. The good news is yes, there is. The bad news is no, there isn't. Sound confusing? Let me explain...
You can set up a custom format that will display your time in any format you want. For instance, you could use the following steps:
Select the cells you want to use for time input.
Choose Format from the Cells menu. Excel displays the Format Cells dialog box.
Make sure the Number tab is displayed.
In the Category list, choose Custom.
Replace whatever is in the Type box with #":"00.
Click on OK.
You can now enter your times using just digits. The problem (and this is the bad news) is that the cell doesn't really contain a time. If you enter 230 (for 2:30), it doesn't contain 2:30 as a timeāit contains two hundred and thirty. Thus, you can't use the contents of the cell directly in time calculations.
To overcome this, you can use another column to show the entered digits converted into a time. All you need to do is use a formula to do the conversions. For instance, if the time you entered was in cell A3, you could use the following formula in a different cell to do the conversion:
=(INT(A3/100)/24)+((A3 - (INT(A3/100)*100))/1440)
Format the cell that contains the above formula so it displays one of the various time formats, and you are all set.
(Full article and more at the source.)
This post may help you...
Formatting MM/DD/YYYY dates in textbox in VBA
I have an excel document with about 500 rows.
I need to format all the cells in , let's say, B column from date to text.
This is how it looks like now:
2012-06-15
2012-06-01
2012-06-14
What it looks like when formated to text:
41075
41061
41074
It has come to my understanding that this is a timestamp representing days since 1st januari 1900, right? Anyhow, this is not what I want. I want the value of the field to be exactly what it is but with the column type of text. I've found various solutions for this using functions like this: =TEXT(B1, "yyyy-mm-dd") but that is not reformating the cell, it is extracting a value from one cell, reformat it and represent is as text in another.
The rule I'm after: I want all cells in B column to have the type text without changing the value
Thanks!
If you have a situation where columns A to D are dates of 500 rows you then:
Use the =TEXT(A1, "yyyy-mm-dd") function you describe in cell E1.
Copy this formula 4 columns wide, and 500 rows down.
Then copy and paste values to the preceding cells.
Copy Example:
Output:
You're right, Excel stores dates internally as number of days since January 1st, 1900 (apart from a minor leap year bug).
Thus, I'm afraid you cannot have both:
Either you keep the value e.g. (41075) and simply format it as a date, so it'll be displayed as 2012-06-15 -
Or you convert it to text format - but then you either
Lose the underlying value - if you convert it to the format you wish with a text function as you mentioned
Keep the value (41075), but cannot see the date
If you are typing in the values you can by adding a ' before the values to keep it as text.
e.g.
But depending on the method the third party service uses to import these values this may not work and I bet you will not get around it unless you export it to a text editor and import it again.
Also try to play with diferent types of text for your third party service, e.g. "2012-06-15" as some see the quotes and remove them.
Here is a list of dates:
04-22-11
12-19-11
11-04-11
12-08-11
09-27-11
09-27-11
04-01-11
When you copy this list in Excel, some of them are recognized as dates, others not, in the following manner:
04-22-11
12-19-11
11-04-11 (date)
12-08-11 (date)
09-27-11
09-27-11
04-01-11 (date)
Does anyone know why? And how to force Excel to recognize all list items as dates?
Many thanks!
It is caused by Excel auto-recognizing/formatting the cell contents, but in unclear/inconsistent ways.
Fixing it is not that hard...
Check out this forum post:
http://www.pcreview.co.uk/forums/excel-not-recognizing-dates-dates-t3139469.html
The steps in short:
Select only the column of "dates"
Click Data > Text to Columns
Click Next
Click Next
In step 3 of the wizard, check "Date" under Col data format, then
choose: "DMY" from the droplist.
Click Finish
This is caused by the regional settings of your computer.
When you paste data into excel it is only a bunch of strings (not dates).
Excel has some logic in it to recognize your current data formats as well as a few similar date formats or obvious date formats where it can assume it is a date. When it is able to match your pasted in data to a valid date then it will format it as a date in the cell it is in.
Your specific example is due to your list of dates is formatted as "m/d/yy" which is US format. it pastes correctly in my excel because I have my regional setting set to "US English" (even though I'm Canadian :) )
If you system is set to Canadian English/French format then it will expect "d/m/yy" format and not recognize any date where the month is > 13.
The best way to import data, that contains dates, into excel is to copy it in this format.
2011-04-22
2011-12-19
2011-11-04
2011-12-08
2011-09-27
2011-09-27
2011-04-01
Which is "yyyy-MM-dd", this format is recognized the same way on every computer I have ever seen (is often refered to as ODBC format or Standard format) where the units are always from greatest to least weight ("yyyy-MM-dd HH:mm:ss.fff") another side effect is it will sort correctly as a string.
To avoid swaping your regional settings back and forth you may consider writting a macro in excel to paste the data in. a simple popup format and some basic logic to reformat the dates would not be too difficult.
In your case it is probably taking them in DD-MM-YY format, not MM-DD-YY.
The quickest and easiest way to fix this is to do a find and replace on your date seperator, with the same separator.
For example in this case Find "-" and Replace with "-", not sure why this works but you will find all dates are right-aligned as they should be after doing this.
Here is what worked for me. I highlighted the column with all my dates. Under the Data tab, I selected 'text to columns' and selected the 'Delimited' box, I hit next and finish. Although it didn't seem like anything changed, Excel now read the column as dates and I was able to sort by dates.
The simplest solution is to put yy,mm,dd into the date() formula by first extracting them with left(), mid() and right(). In this case, assuming your input date is in A1:
=date(right(A1,2)+100,left(A1,2),mid(A1,4,2))
Explanation of above:
=right(A1,2) gets the last two digits in the cell (yy). We add 100 because it defaults to 1911 instead 2011 (omit +100 if it doesn't do that on yours)
=left(A1,2) gets the first two digits in the cell (mm).
=mid(A1,4,2) gets 2 digits in the middle of the cell, starting at 4th digit (dd).
Why this happens in the first place:
I come across this problem all the time when I import Canadian bank data into excel. In short, your input date format does not match your regional settings.
Seems your setting mean Excel wants date input as either DD-MM-YY or YY-MM-DD, but your input data is formatted as MM-DD-YY.
So, excel sees your days as months and vice-versa, which means any date with day below 12 will be recognized as a date, BUT THE WRONG DATE (month and day reversed) and any date with day above 12 won't be recognized as a date at all, because Excel sees the day as a 13th+ month.
Unfortunately, you can't just change the formatting, because Excel has already locked those day/month assignments in place, and you just end up moving what Excel THINKS are days and months around visually, not reassigning them.
Frankly, it is surprising to me there is not a date-reverse tool in excel, because I would think this happens all the time. But the formula above does it pretty simply.
NOTE: if your dates don't have leading zeros (i.e. 4/8/11 vs 04/08/12) it gets trickier because you have to extract different amounts of digits depending on the date (i.e. 4/9/11 vs 4/10/11). You then have to build a couple if statements in your formula. Gross.
Here is what worked for me on a mm/dd/yyyy format:
=DATE(VALUE(RIGHT(A1,4)),VALUE(LEFT(A1,2)),VALUE(MID(A1,4,2)))
Convert the cell with the formula to date format and drag the formula down.
Right-click on the column header and select Format Cells, the chose Date and select the desired date format. Those that are not recognized are ambiguous, and as such not interpreted as anything but that is resolved after applying formatting to the column. Note that for me, in Excel 2002 SP3, the dates given above are automatically and correctly interpreted as dates when pasting.
A workaround for this problem consists in temporarily changing your regional settings, so the date format of the CSV imported file "matches" the regional settings one.
Open Office seems to work in a similar way for that issue, see: http://www.oooforum.org/forum/viewtopic.phtml?t=85898
I come across this problem when I tried to convert to Australian date format in excel. I split the cell with delimiter and used the following code from split cells then altered the issue areas.
=date(dd,mm,yy)