VB6 simple date problem

Posted on 2006-04-05
Last Modified: 2011-04-14

I am using Windows 2000 professional and Vb6

The command I have tested is as follows:-
Private Sub Command1_Click()
   Dim a As Date
   a = #4/19/2006#
   MsgBox Weekday(a) & " " & WeekdayName(Weekday(a)) & " " & a
End Sub

The result I got from one system is
'4 Thursday 19/04/2006

The result I got from another system is
'4 Wednesday 19/04/2006

I am not able to understand how to resolve this issue.

Hoping for immediate reply.

Question by:sriramiyer
    LVL 4

    Expert Comment

    Try using the  firstdayofweek option (where 1=sunday, 2=monday. etc)..

    Weekday(date, [firstdayofweek])

    MsgBox Weekday(a) & " " & WeekdayName(Weekday(a)) & " " & a , 1 'Start on Sunday

    This should sort the problem as it will use this variable instead of the machine defaults.

    LVL 17

    Accepted Solution

    There are some problems with first day of week if the PC settings are changed. to stop this problem you can use format the dddd gixes you week day name:

    msgbox Format(A,"dddd dd/mm/yyyy")

    Also this is a good idea, if you PC should be using non-usa date format when you app starts:

    If DateSerial(2006,9,11)<>DateValue("11/9/2006") Then
       MsgBox "You regional settings date format is set fo USA mode and may cuase problems when working with databases."
    End If
    LVL 5

    Author Comment

    Thanks to inthedark. It works fine.


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to improve team productivity

    Quip adds documents, spreadsheets, and tasklists to your Slack experience
    - Elevate ideas to Quip docs
    - Share Quip docs in Slack
    - Get notified of changes to your docs
    - Available on iOS/Android/Desktop/Web
    - Online/Offline

    Introduction In a recent article ( for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
    When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
    As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
    This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    8 Experts available now in Live!

    Get 1:1 Help Now