I am struggling with formatting dates in Excel and am looking for some help.
I have two different date formats in the same column:
MM/DD/YYYY
DD/MM/YY
I am struggling to change the DD/MM/YY to MM/DD/YYYY. I have tried so many things and can't get it to work.
Public Function dateguesser(inDate As String) As Date
dateguesser = CDate(Split(Split(inDate, " ")(0), ",")(0))
End Function
Things I have tried:
This solution ends up thinking that the DD in the DD/MM/YY format is the year because the year is not stored as four digits.
Tried to change MM/DD/YYYY to DD/MM/YY and then convert all of them to MM/DD/YYYY.
Text to columns
If you put this formula starting in B3, I think it should work for all values?
=IF(ISNUMBER(A3),A3,DATE(2000+RIGHT(A3,2),MID(A3,4,2)+0,LEFT(A3,2)+0))
You could also probably modify your custom function to something like this:
Public Function dateguesser(inDate As Variant) As Date
If IsNumeric(inDate) Then
dateguesser = inDate
Else
dateguesser = CDate(Split(Split(inDate, " ")(0), ",")(0))
End If
End Function
I'd add another column to convert to epoch and back to new date format. https://exceljet.net/formula/convert-unix-time-stamp-to-excel-date could help
Assuming the input is in A10:A11, I made for B10:
=((A10-DATE(1970,1,1))*86400/86400)+DATE(1970,1,1)
and applied new date format to B:B.
I have an Userform where you get the dates from a Table. The Dates in this Table are in "dd/mm/yy" format. When you get the Dates it appears like this:
I can write a new date on either of the textboxes and with the Modify Button I can modify the dates in my Table.
The problem is that when the new dates appear in the Table, they change format and turn into mm/dd/yy.
I'm already using format when putting the date in the text box and when puting it in the Table:
'putting date in Text Box:
FMDateEditor.tbFechaRecibida.Text = Format(MainCode.myRange.Cells(MainCode.EditIndexFechas, shMaster.ListObjects("MasterTable").ListColumns("Fecha recibida").index).Value, "dd/mm/yy")
'
'Puttting date in Table:
MainCode.myRange.Cells(MainCode.EditIndexFechas, shMaster.ListObjects("MasterTable").ListColumns("Fecha recibida").index).Value = Format(FMDateEditor.tbFechaRecibida.Text, "dd/mm/yy")
But the problem Persists
The cells in the Table have "dd/mm/yy" format.
Thanks for the help
Excel stores dates as a number representing the mm/dd/yyyy format and performs all its calculations in this format. So avoid applying date formats when assigning from a variable to a variable (or using in calculations)
Try:
FMDateEditor.tbFechaRecibida.Text = _
Format(MainCode.myRange.Cells(MainCode.EditIndexFechas, _
shMaster.ListObjects("MasterTable"). _
ListColumns("Fecha recibida").Index).Value, "dd/mm/yy") & ""
I have a column in Excel Sheet which contains all the dates in custom dd-mm-yyyy format. I need to convert all these dates to text without losing the format. If I am changing the cell format to Text, I am losing the format. I tried to copy the cell values as values but did not work. I searched a lot on the internet, but did not find any useful resource. What's the possible solution?
Try using the TEXT function.
=TEXT(A1,"dd-mm-yyyy")
Use this formula for keeping the long date format from "A1" cell in another cell (exp: "B1"):
=TEXT(A1,"[$-F800]dddd, mmmm dd, yyyy")
The cell "A1" is a cell contains a date (such as today date with «today()» formula) with long date format.
Also, you can use this VBA code for getting same format with specify font and size in print's header:
ActiveSheet.PageSetup.RightHeader = "&""Arial Rounded MT Bold,Regular""&16" & Range("B1").Value
This code will shows the "B1" cell (as a text from "A1" cell) in Right of Header in Print.
I have a cell with the following content:
01/02/2015
The cell is date formatted.
Then I copy the value and put it in my module class:
Set Line = New CTravelLine
Line.Date= Cells(1, 8).value
Everything works fine until the moment I put this value in another cell:
The value 01/02/2015 becomes 02/01/2015.
I am using this format (dd/mm/yyyy). I have the impression that when the days are numerically lower than the month, the 2 values are reversed. The values are reversed whatever the method I tried:
Method 1:
Dim WrdArray() As String, datetest As String
WrdArray() = Split(travelLine.Date, "/")
datetest= WrdArray(0) & "/" & WrdArray(1) & "/" & WrdArray(2)
Cells(5, 5) = datetest
Method 2:
Cells(5, 5) = travelLine.Date
I don't understand how I can solve this problem.
This might have happened due to 'Regional formatting problem'.
Excel has a habit of forcing the American date format (mm/dd/yyyy) when the dates have been imported from another data source. So, if the day in your date happens to be 1 - 12, then Excel will switch the date to mm/dd/yyyy.
When dates are imported from a text file, there is an option in the VBA code to apply regional format which corrects this problem.
OR
Change number format of date column in excelsheet from 'date' format category to 'text'; save it.
(After Saving run the VBA Code if you have any. Now check whether the date format is 'text' or changed back to 'date'.)
If it has changed back to 'date' try to fix it as 'text'
If it's 'text'; Correct the erroneous date cells and save the excel sheet. This will make dates not to change automatically to American Format.
Long story short, I had a similar problem where the dates are working just fine in some cells but keep flipping in others regardless if I copy paste or enter manually, I did the whole data text to column and cell formatting solutions and all of that didn't work.
The solution actually is not in excel, it's in the region and language setting.
To have the dates display as MM/DD/YYYY in the formats tab change the format to US.
To have the dates display as DD/MM/YYYY in the formats tab change the format to UK.
I had the same issue as you .
Let me explain what I want to do :
I have a csv file with some date.
I copy a range of my sheet in variable table. The range contain some columns with dates.
I make some manipulations on my table (very basic ones)
I transpose my variable table (since only the last dimension of a variable table can be increase)
I put my variable table on a new sheet.
What I found:
There is no date issue after executing step 1-4. The date issue shows up when writing on the sheet...
Considering what Avidan said on the post of Feb 24 '15 at 13:36, I guess it is excel which forces the American format mm/dd/yyyy... So I just change the date format at the very beginning of my program :
Before starting any manipulation date:
do
.Cells("where my date is") = Format(.Cells("where my date is"), "mm dd yy")
execute your program
write the table on a sheet
back up to the date format you like directly on the sheet
Just use:
Line.Date = cDate(Cells(1, 8).value2)
I have imported a CSV file with 2 long columns of dates. These dates are in the US format Aug/28/2013 and I want them to be in the standard UK dd/mm/yyyy format.
I have tried formatting the cells as US dates and then converting them to number-only formats, and various other permutations within the Date format box, but with no success.
Can anyone rid me of these awful US dates please?
Another solution without using a formula:
Select the relevant columns
Choose Data → Text to Columns…
Select “Delimited” and click Next
Untick all delimiters and click Next
Select data column format “Date: MDY” and click Finish
The dates should now be converted to UK dates.
The problem is that a US date can parsed by Excel as a UK date when the day is less than 13. When this happens Excel converts it to the localized UK serial (date) number.
So 03/19/2014 is obviously a US date of the 19th of March. However 05/03/2014 is ambiguous so Excel parses it the local date format as the 5th of March, rather than the US 3rd of May. Any formula has to check if Excel has stored the US Date as a UK date. A UK date will be stored in Excel as a number.
=IF(ISNUMBER(A2),DATE(TEXT(A2,"yyyy"),TEXT(A2,"dd"),TEXT(A2,"mm")),DATE(RIGHT(A2,4),LEFT(A2,FIND("/",A2)-1),MID(A2,FIND("/",A2)+1,2)))
(For a US date in cell A2 and PC date is dd/mm/yy).
If ISNUMBER is true, the US date looks like a UK date and Excel has serialized it as a number. So can format the date as text and back to a date again. Note day is passed to the month parameter of the first DATE function to perform the conversion.
If ISNUMBER is false, its stored as a string as Excel doesn't convert a date string with >12 months. So use string functions to split it up for the DATE function.
I'm assuming that the date you received is formatted as text and that simply formatting it as date is not changing anything. You can run the following formula on the date:
=(MID(A1,FIND("/",A1)+1,FIND("/",A1,FIND("/",A1)+1)-FIND("/",A1)-1)&"-"&LEFT(A1,FIND("/",A1)-1)&"-"&RIGHT(A1,4))*1
If you get numbers, you just need to format it as dd/mm/yyyy and it should be good.
I tried some of the other suggestions but none seemed to work for me. In my case I was importing US dates in the form M/d/yyyy hh:mm:ss. If you don't mind using some VBA in your spreadsheet then the following function did the job for me:
Public Function USDate(ds As Variant) As Variant
Dim sp() As String
Dim spt() As String
Dim spt2() As String
If ds = vbNullString Then
USDate = ""
ElseIf IsNumeric(ds) Then
' Convert numeric US dates wrongly interpreted as UK i.e. 1/7/2017 as 7th January 2017
USDate = DateSerial(Year(ds), Day(ds), Month(ds))
Else
sp = Split(ds, "/") ' split the date portion
spt = Split(sp(2), " ") ' split the time from the year
spt2 = Split(spt(1), ":") 'split the time hms
USDate = DateSerial(spt(0), sp(0), sp(1)) + TimeSerial(spt2(0), spt2(1), spt2(2))
End If
End Function
Thanks for https://stackoverflow.com/users/845584/peterx pointing out - you will need to create the function in a VBA code module to use this technique.
Simply use it in a spreadsheet formulae for example =USDate(A2)
Related to this, the below simply formula can be helpful for changing a date from
"MM/DD/YYYY"
into
"DD/MM/YYYY".
=VALUE(TEXT(B2,"mm/dd/yyyy"))
We can get best of both world with this more concise formula:
=IF(ISNUMBER(A2),VALUE(TEXT(A2,"mm/dd/yyyy")),DATE(RIGHT(A2,4),LEFT(A2,FIND("/",A2)-1),MID(A2,FIND("/",A2)+1,2)))
Can't find anything shorter.
There was one more issue for me, as somehow the raw data was supposed to be read as a number, but it did not. Hence, i updated the formula with 1 final case:
=IFERROR(IF(ISNUMBER(A2),VALUE(TEXT(A2,"mm/dd/yyyy")),DATE(RIGHT(A2,4),LEFT(A2,FIND("/",A2)-1),MID(A2,FIND("/",A2)+1,2))),DATE(RIGHT(A2,4),LEFT(A2,FIND("/",A2)-1),MID(A2,FIND("/",A2)+1,1)))
This can be tricky when the dates in mixed format eg. UK and US in the same column. I have found an effective if inelegant solution:
Step1) Select the column containing the dates to be converted;
Step2) Format, Cells, Text;
Step3) Format, Cells, Date, US;
Step4) Data, Text to column, Next, Delimited, Next, delete all delimiters, Next, select format MDY;
Step5) Format, Cells, Date, UK.
Step4 had been suggested elsewhere, but that on it's own didn't do it for me. I am hoping to combine these steps into a macro but no success this far.
I couldn't get the most common answer to work, the process that worked for me was:
For date 10/04/2018 11:49:20, right-click cell and "Format Cells", "Number" tab and select "Custom" Category and then select mm/dd/yyyy hh:mm.
Assuming that you start with a string (and not an internal excel date number that is just formatted as US format - which is an easy fix), can someone tell me why this method doesn't work?
Use the DATEVALUE / TIMEVALUE functions to convert it into an excel internal formatted date number (You might need to MID() the string in case there are extra bits before or after).
Just make sure that your regional settings match the input date format (otherwise DATEVALUE will fail and you will get a #VALUE error).
Then set the cell format to display the way you want it (Custom format e.g. "dd/mm/yyyy hh:mm:ss").
If you also want to change the timezone, you can add on (hours/24) to the internal Excel excel formatted date number.
The above look impressively complex! Why any country should settle on a non-sequential date format escapes me! Say you have a US-format date (mm/dd/yy) in cell A1. To convert this to dd/mm/yy format as in the UK, just do:
=CONCATENATE(MID(A1,4,2),"/",MID(A1,1,2),"/",MID(A1,7,2))
This certainly works in LibreOffice and I hope also in Excel.