Solved

Date Formats and Date Data Types

Posted on 1999-01-05
11
163 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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
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

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

Suggested Solutions

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

831 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