Date format conversion in Excel - excel

I have a list of dates, which seem to be in dd/mm/yyyy hh:mm format ( Ex - 12/13/2022 12:16 AM ) , which is incorrect. I need to change to mm/dd/yyyy hh:mm format.
I tried the formula =IF(H2="","",IF(DAY(H2)>12,DAY(H2)&"/"&MONTH(H2)&"/"&YEAR(H2),VALUE(DATE(YEAR(H2),DAY(H2),MONTH(H2)))))
but the result is #Value

You seem to be missing the point: a datetime format in Excel is a normal number, where 1 means one day, starting at the first of January, 1900.
Let me show how it looks on my PC:
As you can see, there are two ways to describe the thirteenth of December, 2022:
format dd/mm/yyyy : 13/12/2022 (European style)
format mm/dd/yyyy : 12/13/2022 (American style)
But as you can see below, the actual values are the same (44908 is the amount of days starting at January first 1900).
Doing calculations on this, like checking =DAYS()>12, has no meaning, because the days will be calculated from that 44908 number, not from the way it's displayed.
So, don't start formulas on that, just alter the way it's displayed (using cell formatting, as shown in my screenshot).

Related

Question on formatting dates as text in excel

I have two sets of data. One has dates in the format Jan 10, 2020 which is stored as text. The other format is dd/mm/yyyy and is not text.
I'm trying to check if the dates are equal but I can't get it to work.
I've removed the , in the text stored date. I've tried using the Datevalue function but it just returns #value. The date function also doesn't work...
Any help appreciated.
Thanks.
Not all text strings are suitable for DateValue(). It works best when the day, month and year representation are in the order that your regional settings expect. If you are on UK settings, then you want DMY order, but the date text is in MDY order.
Therefore, you need to transform the text string into something that Datevalue() can process, for example
=DATEVALUE(MID(A1,5,FIND(",",A1)-5)&"-"&LEFT(A1,3)&"-"&RIGHT(A1,4))
This formula works for one- or two-digit days.
Format the result as date and use it for your comparison.

Excel convert text (April 1, 2017) to date

I have some dates in my Excel spreadsheet that are in this format to change it to convert to a date format of dd/mm/yyyy, or any form that allows me to sort by date.
How would I be able to do this using a formula? April 1, 2017 = 01/04/2017
Thanks!
P.s. I've looked through the question: How to convert the text to date format in excel
It looked similar, but the formula doesn't work even when I take out the timevalue portion.
If the "date" is being read as text, and your "date" format will always be mmmm d, yyyy, you can try the following (assuming cell A1 has the "date"):
=DATE(RIGHT(A1,4),MONTH(LEFT(A1,3)&1),MID(A1,FIND(" ",A1)+1,FIND(",",a1)-FIND(" ",A1)-1))
After which, you can just set a custom dd/mm/yyyy format to that date. OR you can enclose the formula above in a TEXT() function:
=TEXT(DATE(RIGHT(A1,4),MONTH(LEFT(A1,3)&1),MID(A1,FIND(" ",A1)+1,FIND(",",a1)-FIND(" ",A1)-1)),"dd/mm/yyyy")
What I would recommend, however, is using the first formula and setting a custom format.

Using weeknum on date and time text results with #VALUE

So my friend has this template he got from his boss, it's got a bunch of dates and times and other data. He told me he created a new workbook and copied everything from the template to this new workbook and then he modified the dates. The date and time listing he copied from another file.
So this is where the problem occurs, when he's done copying, one entire column resulted with #VALUE! instead of expected result w/c would be in yy/ww format. The formula is written below:
=MID(N2,9,2)&"/"&IF(LEN(WEEKNUM(N2,1))=1,"0"&(WEEKNUM(N2,1)),(WEEKNUM(N2,1)))
Inside N2 is 26/08/2014 1:27 PM. So I googled a bit and found out that WEEKNUM doesn't work for text-style date and time. Should only work with serial numbers, if I understand it correct. I checked the N column (which was all copied from another file) and they were all in text. But when I checked the template, the dates were also all in text style. So how the formula worked with the template but not with the new workbook? (I'm assuming that every text in every cell is aligned to the left, dates in both new workbook and the template are both aligned to the left.)
I told my friend that the N column should be in date format so I suggested him this formula:
=(DATE(2014,8,26) + TIME(13,27,0))
And finally it worked. But his and my concern would be that we can no longer just copy and paste the dates but manually input every date within the formula. But there's just too many dates and it would take a long time to finish.
Any way around this?
UPDATE:
I just noticed something. The format of the dates copied is dd/mm/yyy h:mm AM/PM. When I checked on the column where all the #VALUE!s are spawning, there are exceptions. I actually found 3-4 cells that are normal.
The date is: 02/10/2014 3:49 PM and the result with using the formula is 15/49. I'm wondering, could it have been with how the dates are typed in? Or rather copied in? Like, should the date format be in mm/dd/yyyy instead of dd/mm/yyyy?
Used evaluate formula and it said that N2 contains a constant.
The WEEKNUM function works with dates as text while it can implicitly convert the text to date. Example:
Input '31/03/2015in A1 and =WEEKNUM(A1) in B1. Input '03/31/2015 in A2 and =WEEKNUM(A2) in B2. Note the leading ' before the dates. They will convert the inputs to text. One of them will work, one will not. This will indicate which is your default date format dd/mm/yyyy or mm/dd/yyyy.
You say both Excel are English but there is a difference in default date format between GB English and US English unfortunately.
So if the dates are text in dd/mm/yyyy format and your default date format is mm/dd/yyyy, you can't simply copy them into your Excel and work with them. You have to change them ever to mm/dd/yyyy first. Ever, because even the values which seems to work are mostly wrong. WEEKNUM with the text 09/11/2015 will work even with default date format mm/dd/yyyy. But it will implicitly convert the text to September 11. 2015 while with dd/mm/yyyy 09. November 2015 was meant.
Best solution ist not to use dates in text format. If your friend's boss had used date values instead of text then copy&paste would work. But because he had not, you have to convert the formats in a helper column now. Try
=MID(N2,4,2)&"/"&LEFT(N2,2)&"/"&MID(N2,7,999)
copied down in a helper column.

Format code for a date with time zone in excel

I have date value with a time zone.
24 Nov 2005 GMT+05:30
What is the format code for this custom format in Excel?
I tried dd MMM yyyy with z,zz,zzz, and Z but Excel ignores those options.
Not sure if possible. I've just gone through every letter in custom format cell and nothing looked right.
What I would suggest is maybe splitting it up into a few cells and then bringing them all together.
In the first column (A1) you could have the date, formatted how you like (dd mmm yyyy).
Second (B1) you could have the time before you account for the different timezone (formatted how you like, i.e. hh:mm:ss.
Third (C1) define if the timezone is ahead or behind with a plus/minus sign.
Fourth (D1) you could set the time difference (i.e. your example +5:30). Format the cell as h:mm.
Fifth (E1), enter the formula: =IF(C1="+",B1+D1,IF(C1="-",B1-D1)). Format the cell as hh:mm:ss.
Finally, (F1) there's two options for you. You can combine the date and time adjusted to the timezone, or you can combine the date, original time and include timezone.
The first option would be: =TEXT(A1,"dd mmm yyyy ")&TEXT(E2,"hh:mm:ss")
Second would be: =TEXT(A1,"dd mmm yyyy ")&TEXT(B1,"hh:mm:ss ")&"GMT"&TEXT(C1,"")&TEXT(D1,"h:mm")
This is the absolute best solution I could think of. Sorry if it's not what you asked for.

Convert number to YYYYMM

I have following numbers, which actually represent dates in the YYYYMM format:
201301
201302
201303
...
When I try to format the cells to date fields, Excel always overwrites the original dates and creates some crazy dates, that have nothing in common with the actual ones.
How can I bring Excel to convert it properly?
Excel (by default) uses the 1900 date system. This simply means that the date 1 Jan 1900 has a true numeric value of 1, 2 Jan 1900 has a value of 2 etc. These values are called "serial values" in Excel and it is these serial values that allows us to use dates in calculations. which was discussed here.
So that explains why your data reflects a different date when you try to format is as Date.
What you need to do then is to transform it into a complete readable date format Excel recognize.
As is, Excel will use its default Serial Value conversion.
If you have your data in starting in A1, enter this in B1.
=DATEVALUE(SUBSTITUTE(A1,LEFT(A1,4),LEFT(A1,4)&"-")&"-01")
Above formula will then create a valid Date that Excel can interpret and read correctly.
Result will be:
41275
41306
41334
When you format it as Date, it will equate to the 1st day of every month.
1/1/2013
2/1/2013
3/1/2013
You can just fix the formatting using Custom Format to get YYYYMM as seen below:
If your range is small enough (in the example all 2013) then no formula is required. Replace 13 with 13-, apply Text to Columns with Tab as the delimiter and at Step 3 choose Date and YMD.
You can use the DATE and LEFT/RIGHT functions.
Assuming that format is consistent (i.e. 4 characters for year, 2 characters for month), to convert cell A1:
=DATE(LEFT(A1,4), RIGHT(A1,2), 1)
This will assume the first day of the month for the date (I assume that's irrelevant for you). You can then format the cell as you want.
Can you use formula in Excel to solve this..
A sample formula is given below
=DATE(MID(CELLID,1,4),MID(CELLID,5,2), 1)

Resources