Convert to Date "dd-mm-yyyy"

vmjan02

Well-known Member
Joined
Aug 15, 2012
Messages
1,132
Office Version
  1. 365
  2. 2021
  3. 2019
  4. 2016
  5. 2013
I have a row from H8 to BC8 in this format, is there aw way vba code to convert it to dd-mm-yyyy


24/06/22, 00:0024/06/22, 01:0024/06/22, 02:0024/06/22, 03:0024/06/22, 04:0024/06/22, 05:00
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
On the Home tab, click the Dialog Box Launcher next to Number. You can also press CTRL+1 to open the Format Cells dialog box. In the Category box, click Date or Time, and then choose the number format that is closest in style to the one you want to create.
 
Upvote 0
I have a row from H8 to BC8 in this format, is there aw way vba code to convert it to dd-mm-yyyy


24/06/22, 00:0024/06/22, 01:0024/06/22, 02:0024/06/22, 03:0024/06/22, 04:0024/06/22, 05:00
1. Highlight all the dates
2. Right-click
3. Format cells
4. Under "Category" choose "Date"
5. Under "Type" choose which type you want

If the right type doesn't exist:

1. Choose "Custom" under category
2. In the "Type" field, type how you would like the date to display

For example, typing: dd-mm-yyyy
Will convert the date value to look like: 01-01-2023

For example, typing: dddd, d mmmm yyyy
Will convert the date value to look like: Sunday, 1 January 2023

And so on
 
Upvote 0
Hi Chris and Lighting i tried both of your methods but non is working out for me.
it is still giving me the sale result as 24/06/22, 00:00 no change.
 
Upvote 0
Hi Chris and Lighting i tried both of your methods but non is working out for me.
it is still giving me the sale result as 24/06/22, 00:00 no change.
I see, think I’ve had this before with a report produced from a HR system.

Can you upload the sheet via XL2BB and I can look at it
 
Upvote 0
I see, think I’ve had this before with a report produced from a HR system.

Can you upload the sheet via XL2BB and I can look at it
Hi please find attached.
 

Attachments

  • Date.jpg
    Date.jpg
    109 KB · Views: 15
Upvote 0
The comma in your original post and the fact that formatting doesn't change it indicates it is text.

Try one of these.

20230619 DateTime Conversion vmjam02.xlsx
ABCDEFG
1
2Original Line (looks to be text) --->24/06/22, 00:0024/06/22, 01:0024/06/22, 02:0024/06/22, 03:00
3
4
5Converted to Date Time --->24-06-2022 00:0024-06-2022 01:0024-06-2022 02:0024-06-2022 03:00
6(Applied custom format of dd-mm-yyyy hh:mm)
7
8Converted to Date Text --->24-06-2022 00:0024-06-2022 01:0024-06-2022 02:0024-06-2022 03:00
9
10
Sheet1
Cell Formulas
RangeFormula
C5:F5C5=--(SUBSTITUTE(C2,",",""))
C8:F8C8=TEXT(--(SUBSTITUTE(C2,",","")),"dd-mm-yyyy hh:mm")
 
Upvote 0
Another option, with vba:
This will remove the time part, and keep the date only.
VBA Code:
Sub TO_DATE1()
Dim c As Range
For Each c In Range("H8:M8")
    If Len(c) > 7 Then c = CDate(Left(c, 8))
Next
Range("H8:BC8").NumberFormat = "dd-mm-yyyy"
End Sub
 
Upvote 0
This is what i was looking for, thanks a ton Akuini
thanks a lot Alex your formula is also perfect, but needed a vba code.
 
Upvote 0

Forum statistics

Threads
1,223,897
Messages
6,175,270
Members
452,628
Latest member
dd2

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top