Solved

Date Formats and Date Data Types

Posted on 1999-01-05
11
165 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
ID: 1454018
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
ID: 1454019
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
ID: 1454020
Also no problems when I change my short date format.
I'm using VB6 on NT
0
Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

 
LVL 13

Expert Comment

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

Expert Comment

by:caraf_g
ID: 1454022
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
 
LVL 10

Expert Comment

by:caraf_g
ID: 1454023
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
ID: 1454024
that should read ... and back to your normal one again (etc.)
0
 

Author Comment

by:paul_gilowey
ID: 1454025
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
ID: 1454026
????????????????????????????????????????????????
0
 
LVL 10

Expert Comment

by:caraf_g
ID: 1454027
Hmm... welcome to the twilight zone! ???
0
 

Author Comment

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

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

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…
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…
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…
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…

726 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