Inconsistent results with date values

Yamezz

Active Member
Joined
Nov 22, 2006
Messages
334
Office Version
  1. 2019
I have the code:
Code:
Dim InvDate As Date

InvDate = Sheets("Sale").Range("SaleDate").Value
InvDate = Format(InvDate, "dd/mm/yyyy")
MsgBox InvDate
MsgBox Month(DateAdd("m", -1, InvDate))
MsgBox Format(Month(DateAdd("m", -1, InvDate)), "mmm")
which, when supplied the date 01-Sep-14, gives different results for my msgbox lines.
MsgBox InvDate returns "1/09/2014", which is correct.
MsgBox Month(DateAdd("m", -1, InvDate)) returns "8", which is correct.
However, MsgBox Format(Month(DateAdd("m", -1, InvDate)), "mmm") returns "Jan".
It seems in the last line the date format has reverted back to the illogical American format.

How can this be? I need the returned value to be "Aug".
Thanks Guys.
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
Maybe this
Code:
Sub MM1()
Dim InvDate As Date

InvDate = Sheets("Sale").Range("SaleDate").Value
InvDate = Format(InvDate, "dd/mm/yyyy")
MsgBox InvDate
MsgBox Format(InvDate - 1, "m")
MsgBox Format(InvDate - 1, "mmm")
End Sub
 
Upvote 0
Thanks Michael,

That works for 1st September, but I also need it to work for other days in say September - i.e. with all dates assigned to InvDate I would like to get the previous month, hence why I was using DateAdd("m" -1).

Is there a way to convert the "8" output of Month(DateAdd("m", -1, InvDate)) to "Aug"? Could this be the easy way out?
 
Upvote 0
Maybe this
Code:
Sub MM1()
invdate = Format(DateAdd("m", -1, Sheets("Sale").Range("SaleDate").Value), "mmmm")
MsgBox invdate
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,947
Messages
6,122,413
Members
449,082
Latest member
tish101

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