using Format with dates

I wanna change date format in variable.

Date is in format "24.7.1998"
and I want it to be in format "24/7/1998"

I have tryed this but when I look at the NewDate after Format-clause like this "MsgBox NewDate" it has't change at all?

NewDate = Format(Date, "dd/mm/yyyy")
Who is Participating?
clifABBConnect With a Mentor Commented:
From the VB help file:
(/) Date separator. In some locales, other characters may be used to represent the date separator. The date separator separates the day, month, and year when date values are formatted. The actual character used as the date separator in formatted output is determined by your system settings.

Actually what you want is to display the / as a literal.  To do this, you need to put a backslash just before it:

The correct answer is:
MsgBox Format$(DateAdd("d", 1, Now), "DD\/MM\/YYYY")

(By the way, thanks for using four digit year :) )
If NewDate is a date type variable, it will display in your default date format.  As a string variable, it should be displaying as you have formatted it.
if newdate is a date,then you are not going to change it... do this

msgbox format$(newdate, "dd/mm/yyyy")
The new generation of project management tools

With’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

majalaAuthor Commented:
I did this:
Dim NextDay As String

NextDay = Day  'Day is in dd/mm/yyyy format and so is NextDay after this
NextDay = DateAdd("d", 1, NextDay) 'NextDay is in format

NextDay = format(NextDay, "dd/mm/yyyy") 'NextDay is still in format!

Why this isn't working? That $ in anthonyc's answer didn't help either.
by the way.DAY returns an integer..  


?dateadd("d",1, day(now))

I'm SURE this is not what you want.....

if I run this:
msgbox format$(dateadd("d", 1, now), "ddmmyyyy")

I get this in the box

so this works!

majalaAuthor Commented:
That's correct. I did this
MsgBox Format$(DateAdd("d", 1, Now), "DDMMYYYY")
and I got this in box 05081998.

But when I did this
MsgBox Format$(DateAdd("d", 1, Now), "DD/MM/YYYY")
I got this in box 05.08.1998 and I want it to be 05/08/1998.
You could replace the "." for "/"

Option Explicit

Private Sub Form_Load()
    Dim dte As Date
    Dim sNewDate As String
    dte = "24.7.1998"
    sNewDate = sRepl(Format$(dte, "dd/mm/yyyy"), ".", "/")
    MsgBox sNewDate
End Sub

Private Function sRepl(ByVal sInp As String, _
                       ByVal sChar As String, _
                       ByVal sRChar As String) As String
    Dim p As Integer
    p = InStr(sInp, sChar)
    While p > 0
        Mid$(sInp, p) = sRChar
        p = InStr(sInp, sChar)
    sRepl = sInp
End Function

majalaAuthor Commented:
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.