问题
I have an excel sheet created by a 3rd party program.
One of the columns has dates in this format: "Jan 19, 2015 03:00:00 PM"
I would like these dates to appear in the following format: "19/01/2015"
I have selected the cell or cells, right clicked and selected "Format Cells...", chose "Date" in the category, then chose "14/03/2001" in the type, to no avail, the dates won't change.
I also tried "Custom" from the category and "dd/mm/yyyy" from the type, again, no changes at all.
The file is not protected, the sheet is editable.
Could someone explain what I could be doing wrong?
Regards Crouz
回答1:
Given your regional settings (UK), and the inability of formatting to change the date, your date-time string is text. The following formula will convert the date part to a "real" date, and you can then apply the formatting you wish:
=DATE(MID(A1,FIND(",",A1)+1,5),MATCH(LEFT(A1,3),{"Jan";"Feb";"Mar";"Apr";"May";"Jun";"Jul";"Aug";"Sep";"Oct";"Nov";"Dec"},0),MID(SUBSTITUTE(A1,","," "),5,5))
Might be able to simplify a bit with more information as to the input format, but the above should work fine. Also, if you need to retain the Time portion, merely append:
+RIGHT(A1,11)
to the above formula.
回答2:
The following worked for me:
- Select the date column.
- Go to the Data-tab and choose "Text to Columns".
- On the first screen, leave radio button on "delimited" and click Next.
- Unselect any delimiter boxes (everything blank) and click Next.
- Under column data format choose Date
- Click Finish.
Now you got date values
回答3:
I had a similar problem. My Excel sheet had 102,300 rows and one column with date was messy. No amount of tricks were working. spent a whole day entering crazy formulas online to no success. See the snips
- How the column looked ("Short Date" format on Excel)
The red circled cell contents (problematic ones) do not change at all regardless of what tricks you do. Including deleting them manually and entering the figures in "DD-MM-YYYY" format, or copying and pasting format from the blue ones. Basically, nothing worked...STUBBORNNESS!!
- How the column looked ("Long date" format on Excel)
As can be seen, the cell contents doesn't change no matter what.
- How I solved it
The only way to solve this is to:
upload the Excel sheet to Google Drive. On Google Drive do this:
click to open the file with Google spreadsheet
Once it has opened as a Google spreadsheet, select the entire column with dates.
select the format type to Date (you can choose any format of date you want).
Download the Google spreadsheet as .xlsx. All the contents of the column are now dates
回答4:
With your data in A1, in B1 enter:
=DATEVALUE(MID(A1,1,12))
and format B1 as dd/mm/yyyy For example:
If the cell appears to have a date/time, but it does not respond to format changes, it is probably a Text value rather than a genuine date/time.
回答5:
While you didn't tag VBA as a possible solution, you may be able to use what some feel is a VBA shortcoming to your advantage; that being VBA heavily defaulted to North American regional settings unless explicitly told to use another.
Tap Alt+F11 and when the VBE opens, immediately use the pull down menus to Insert ► Module (Alt+I,M). Paste the following into the pane titles something like Book1 - Module1 (Code).
Sub mdy_2_dmy_by_Sel()
Dim rDT As Range
With Selection
.Replace what:=Chr(160), replacement:=Chr(32), lookat:=xlPart
.TextToColumns Destination:=.Cells(1, 1), DataType:=xlFixedWidth, FieldInfo:=Array(0, 1)
For Each rDT In .Cells
rDT = CDate(rDT.Value2)
Next rDT
.NumberFormat = "dd/mm/yyyy"
End With
End Sub
Tap Alt+Q to return to your worksheet. Select all of the dates (just the dates, not the whole column) and tap Alt+F8 to Run the macro.
Note that both date and time are preserved. Change the cell number format if you wish to see the underlying times as well as the dates.
回答6:
Struggled with this issue for 20 mins today. My issue was the same as MARIO's in this thread, but my solution is easier. If you look at his answer above, the blue circled dates are "month/day/year", and the red dates are "day/month/year". Changing the red date format to match the blue date format, then selecting all of them, right click, Format Cells, Category "Date", select the Type desired. The Red dates can be changed manually, or use some other excel magic to swap the day and month.
回答7:
DATEVALUE
function will help if date is stored as a text as in
=DATEVALUE("Jan 19, 2015 03:00:00 PM")
回答8:
Another way to address a few cells in one column that won't convert is to copy them off to Notepad, then CLEAR ALL
(formatting and contents) those cells and paste the cell contents in Notepad back into the same cells.
Then you can set them as Date, or Text or whatever.
Clear Formatting did not work for me. Excel 365, probably version 2019.
回答9:
Select the cells you want to format. Press CTRL+1. In the Format Cells box, click the Number tab. In the Category list, click Date. Under Type, pick a date format.
回答10:
Similar way as ron rosefield but a little bit simplified.
=DATE(RIGHT(A1,4),MATCH(MID(A1,4,2),{"01";"02";"03";"04";"05";"06";"07";"08";"09";"10";"11";"12"},0),LEFT(A1,2))
来源:https://stackoverflow.com/questions/28516923/excel-date-formatting-not-working