Solved

Date Formats and Date Data Types

Posted on 1999-01-05
11
161 Views
Last Modified: 2010-05-03
My short date format is set to dd/mm/yyyy.  If I assign a date field to the following Format(Now,"Short Date") then
the date field converts it to mm/dd/yyyy.  See the following...

Dim dDate as Date
Dim sTempDate as String
Dim sTempFormatedDate as String
Dim sDate as String

dDate = Format(Now,"Short Date")
sTempDate = dDate
sTempFormatedDate = Format(dDate,"Short Date")
sDate = Format(Now,"Short Date")

The current date is 5 January 1999.
The value of dDate when displayed = 01/05/1999
The value of sTempDate when displayed = 01/05/1999
The value of sTempDateFormated when displayed = 01/05/1999
The value of sDate when displayed = 05/01/1999

Only the latter date (sDate) is correct.
Suggestions?

0
Comment
Question by:paul_gilowey
  • 5
  • 4
  • 2
11 Comments
 
LVL 13

Expert Comment

by:Mirkwood
Comment Utility
The code below displayed for times 01/05/99 in my case

Private Sub Command1_Click()
Dim dDate As Date
Dim sTempDate As String
Dim sTempFormatedDate As String
Dim sDate As String

dDate = Format(Now, "Short Date")
sTempDate = dDate
sTempFormatedDate = Format(dDate, "Short Date")
sDate = Format(Now, "Short Date")

MsgBox dDate
MsgBox sTempDate
MsgBox sTempFormatedDate
MsgBox sDate
End Sub

0
 
LVL 10

Accepted Solution

by:
caraf_g earned 50 total points
Comment Utility
Paul,

This is typical behaviour caused by a discrepancy between your short date format and your system date format.

Check that your system date format is set correctly, and agrees with your own short date format.

Example will follow.
0
 
LVL 13

Expert Comment

by:Mirkwood
Comment Utility
Also no problems when I change my short date format.
I'm using VB6 on NT
0
 
LVL 13

Expert Comment

by:Mirkwood
Comment Utility
Caraf_F what do you mean?
short date format == system date format
I think
0
 
LVL 10

Expert Comment

by:caraf_g
Comment Utility
Mirkwood, you're right - Thought I had the answer there but I can't reproduce it either.

Paul - Reject my answer I'm talking ******
Sorry!

Cheers.
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 10

Expert Comment

by:caraf_g
Comment Utility
Erm... still, it mightn't do you any harm to change your Regional Settings in your control panel to "something completely different" and back to your normal one again, and then try your code again. Who knows? Your problem might just go away?

Good luck!
0
 
LVL 10

Expert Comment

by:caraf_g
Comment Utility
that should read ... and back to your normal one again (etc.)
0
 

Author Comment

by:paul_gilowey
Comment Utility
Thank you! It worked.  I changed my date in the regional settings to something else, and the back to dd/mm/yyyy, and
it works.  I wonder how often this may happen to people using
my software.

Thanks for the answer
Paul

0
 
LVL 13

Expert Comment

by:Mirkwood
Comment Utility
????????????????????????????????????????????????
0
 
LVL 10

Expert Comment

by:caraf_g
Comment Utility
Hmm... welcome to the twilight zone! ???
0
 

Author Comment

by:paul_gilowey
Comment Utility
The ACCEPTED answer was'nt actually the accepted on, although the accepted one was by the non-Accepted one.
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

771 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

11 Experts available now in Live!

Get 1:1 Help Now