Solved

Date Formats and Date Data Types

Posted on 1999-01-05
11
162 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
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 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…

911 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

20 Experts available now in Live!

Get 1:1 Help Now