vba help - date format

Mallesh23

Well-known Member
Joined
Feb 4, 2009
Messages
976
Office Version
  1. 2010
Platform
  1. Windows
Hi Team,

I want date format like this. 9. Sep 2020 (Month No & "." & Sep & yyyy")

Date formula gives date :=> 12/09/2020 , how to achieve it. thanks for your help in advance.



Thanks
mg
 
You could just format the date once. ;)
VBA Code:
Format(Date, "yyyy\\m. mmm yyyy\\Re\co\n\\dd.mm.yyyy") & "\abc.xlsx"
 
Upvote 0

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
Hi Peter,

Thanks once again for your help, its working but I have two questions

Format(Date, "yyyy\\m. mmm yyyy\\Re\co\n\\dd.mm.yyyy") & "\abc.xlsx"


why double slashes
In above code Recon is a folder name, if I want to pass variable in its place say ------> " & str_Recon & "

what will be code.


Thanks
mg
 
Upvote 0
why double slashes
I suppose the simple answer is that if you don't, then you don't get a slash generated. \ is a special character in the Format function. Details here

In above code Recon is a folder name, if I want to pass variable in its place say ------> " & str_Recon & "
Then the simplest way would be to split my statement and use two Format() functions

VBA Code:
Format(Date, "yyyy\\m. mmm yyyy\\") & strRecon & Format(Date, "\\dd.mm.yyyy") & "\abc.xlsx"
 
Upvote 0
Maybe something like the below, not sure if you need "9.Sep 2020" or "9. Sep 2020" with a space after the Month number
VBA Code:
Format(Date, "yyyy") & "\" & Format(Date, "m. mmm yyyy") & "\Recon\" & Format(Date, "dd.mm.yyyy") & "\abc.xlsx"
Probably a little more confusing to read, but you can shorten that code snippet to this...
VBA Code:
Format(Date, "yyyy\\m. mmm yyyy""\Recon\""dd.mm.yyyy""\abc.xlsx""")

EDIT NOTE: Just noticed this is similar in concept to what Peter posted in Message #11.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,528
Messages
6,125,342
Members
449,218
Latest member
Excel Master

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