Solved

Date Formats and Date Data Types

Posted on 1999-01-05
11
166 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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…

728 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