How to Change Excel Date Format?
Excel date format related function are grouped in Menu-> Formula -> Date & Time Option. Using this, we can get today's date & time, calculate time differences, format date & time as per our needs. Lets start to learn some basics with Date and Time formula that are available within Excel under these titles.- Get Excel VBA Today Date Functions.
- Excel Convert Number to Date
- Excel VBA Date Format conversion
- Excel Date Format Formula
1. Excel VBA Date Today
To get Excel today's date use one of the following formula in any worksheet.- "=Today()" : will fetch current date from System clock and display in the cell.
- "=Now()": This command will fetch the date along with time from the system clock.
- VBA.Date : To get Excel VBA date today
- VBA.Now : To get VBA date & current tim
2. Excel Convert Number to Date or Date to String
Choose the cell that has data & use the Excel date format conversion as explained below.- Select Excel cell that has Date.
- Right Click & choose "Format Cells" (short cut - 'CTRL + 1').
- Choose 'Number' tab.
- Click 'Custom' under 'Category' list.
- Enter required format under 'Type' or choose a format in any of the defined types.
- Click 'Ok' to complete date formatting changes.
3. Excel VBA Date Format
Use VBA date format codes explained in the below sample code inside your Excel macro. In these sample, there are 4 different methods explained and it only converts the display of Excel VBA date format, not the actual data. It can be considered as converting number to date or string to date, only the visible mode.Sub Excel_VBA_Date_Format()
'Display Date Format in Selection - Jul/21/2016
Selection.NumberFormat = "mmm/d/yyyy"
'Display Date Format in Cell Reference - Thursday, July 21, 2016
ThisWorkbook.Sheets(1).Cells(1, 12).NumberFormat = "[$-409]dddd, mmmm dd, yyyy"
'Display Date Format using WorksheetFunction - Thursday, July 21, 2016
ThisWorkbook.Sheets(2).Cells(2, 12) = Application.WorksheetFunction.Text(42572, "dddd mmmm-dd-yyyy")
'Display Date Format using WorksheetFunction inside Cell - Thursday, July 21, 2016
ThisWorkbook.Sheets(2).Cells(3, 12) = "=TEXT(42573,""mmmm/dd/yyyy"")"
End Sub
Enter different date formats in a new Excel workbook & try the above code to learn how each line make date format conversions.
4. Excel Date Format Formula
Consider the sample date & time value we got from above formulas to explore the available functions. To change this format from numeric date to text with month name like “04-Mar-14”. Then use this Excel Date format formula- =TEXT(TODAY(),"dd-mmm-yyyy") or
- =TEXT(NOW(),"dd-mmm-yyyy")