No "/" in Format result

AlexanderBB

Well-known Member
Joined
Jul 1, 2009
Messages
2,099
Office Version
  1. 2019
  2. 2010
Platform
  1. Windows
? Format("06 Jan 1990", "mm/dd/yyyy")
01 06 1990

Why does it not result in 01/06/1990 like its being told to ??

Using Excel 2007.

Thanks.
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
It works for you Rick ? ? Must be something weird here..

I'm just typing in the immediate window

? format(Datevalue("06 Jan 1990"),"dd/mm/yyyy")
06 01 1990
? format("06 Jan 1990","dd/mm/yyyy")
06 01 1990

The problem arose in code though... and I had to use
Code:
DateIn = .Cells(xRow, "B")
DateIn = Format(DateValue(DateIn), "MM/DD/YYYY")
DateIn = Replace(DateIn, " ", "/")
DateIn = "#" & DateIn & "#"

.cells (xRow, "B") is Formatted as Date Type *14 03 2001
 
Upvote 0
It works for me too (XL2013) - but maybe this alternative?

? format("06 Jan 1990","dd\/mm\/yyyy")
 
Upvote 0
This workbook may be the problem... could it be set somehow to a global Date Format and VBA is sticking with it. no matter what ?
I have tried it with a new instance of Excel though, and no better.

Sorry yosegmail, I dont now how to use TEXT. (I tried it and just got a circular reference error!)
 
Upvote 0
It works for you Rick ? ?
Yes, in both the Immediate Window and in a subroutine executed from the main code window using this code...
Code:
Sub Test()
  Dim S As String
  S = Format("06 Jan 1990", "mm/dd/yyyy")
  Debug.Print S
End Sub
 
Last edited:
Upvote 0
Yes, formR that does work. Hmmm...

I wonder if it is something to do with your regional date settings (maybe your system is expecting dates separated by a dot or has a different meaning for a forward slash) the back slash tells the format function to treat the following character literally.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,178
Members
453,021
Latest member
Justyna P

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