Solved

Date Formatting again q

Posted on 2002-04-14
14
161 Views
Last Modified: 2010-05-02
Dear experts,

Im trying to save the value 18/4/2000 in an SQL 7.0 table field defined as Smalldatetime, but when Iam retrieve that field again it becomes 1/1/1900(the smallest value for such field - smalldatetime)

which format or function should i use to solve that problem
0
Comment
Question by:alhanouty
  • 4
  • 4
  • 2
  • +3
14 Comments
 
LVL 1

Expert Comment

by:ProgramIT
ID: 6939944
You need to save it in DDMMYYYY
In vb for example use strDateVar = format(DBDate,"DD/MM/YYYY")
I try to avoid the preset dates due to similar problems. You can always use CDate to convert back to date formats.
0
 
LVL 45

Expert Comment

by:aikimark
ID: 6940018
you may not be able to store a date this way.  There are some SQLServer restrictions on when you can store dates this way.

The reason you are getting 1/1/1900 is that you are not delimiting your date literal.  Try #18/4/2000#
0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 6940137
Once again you hve fallen behind with your questions. Please maintain the following:
Different Intervals ? Date: 01/21/2002 09:23AM PST
http://www.experts-exchange.com/jsp/qShow.jsp?ta=visualbasic&qid=20257702
moving database file to another computer? Date: 01/14/2002 12:26AM PST  
http://www.experts-exchange.com/jsp/qShow.jsp?ta=mssql&qid=20254826
Date Intervals Problem? Date: 02/01/2002 02:36AM PST  
http://www.experts-exchange.com/jsp/qShow.jsp?ta=mssql&qid=20261970

Thanks,
Anthony
0
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 
LVL 49

Expert Comment

by:DanRollins
ID: 7654052
Hi alhanouty,
It appears that you have forgotten this question. I will ask Community Support to close it unless you finalize it within 7 days. I will ask a Community Support Moderator to:

    Accept aikimark's comment(s) as an answer.

alhanouty, if you think your question was not answered at all or if you need help, just post a new comment here; Community Support will help you.  DO NOT accept this comment as an answer.

EXPERTS: If you disagree with that recommendation, please post an explanatory comment.
==========
DanRollins -- EE database cleanup volunteer
0
 

Author Comment

by:alhanouty
ID: 7667532
Yes I disagree, because non of the above comments solve my problem, so Iam going to delete the question.
0
 
LVL 45

Expert Comment

by:aikimark
ID: 7668082
alhanouty,

We experts started answering your question the very day you asked it, almost nine months ago.  It seemed to us that you abandoned your question.  Welcome back.  

Did you get any resolution to your problem?  That is, did you find a way to save the 18/4/2000 value into the date field?  If so, we'd like so see this solution before the question thread is closed.

Did you give up trying or just work around this by using a different date format?
0
 

Author Comment

by:alhanouty
ID: 7710529
Ok..

I found that you have to use some format function like Format(yourdate,"yyyy-mm-dd ")

thats all

0
 
LVL 49

Expert Comment

by:DanRollins
ID: 7710585
Thanks for the feedback alhanouty.  Your comment indicates that you actually used  ProgramIT's comment.  I am changing my recommendation to:

   Accept ProgramIT's comment(s) as an answer.

==========
DanRollins -- EE database cleanup volunteer
0
 
LVL 45

Expert Comment

by:aikimark
ID: 7711428
I don't get the points, but I agree with DanRollins.
0
 

Author Comment

by:alhanouty
ID: 7723889
Sorry but thats not true because before I ask the Q I know that I have to use the Format function and Im already tried it more than 10 times and when all of them faild to solve the problem , I asked the Question, and No one gave me the solution even ProgramIT's . The trick is not to use the Format function it self, but how to format the string for example : "yyyy-mm-dd" , there is no defaults date format like this format. and if you use ProgramIT's comments the problem will not be the same, and for that I think that no one deserve the points.
(I dont Know if Im right or not)
thankx
0
 
LVL 45

Expert Comment

by:aikimark
ID: 7724860
Here's an idea alhanouty...

Show us a snippet of your code that worked and we'll see if it is sufficiently different from ProgramIT's comment to warrant closing the question with a refund of points.

================================
By the way, what happened when you stored the date using the date-delimiter (#) around your date literal?

My comment diagnosed the reason your date was being stored as 1/1/1900.  So the 'format' of the date needed to be a properly delimited literal.
0
 

Author Comment

by:alhanouty
ID: 7755808

yes

the code I used in the sql statement like:

dim mStr as string
mStr = "Insert Into tablename(smalldatetimefld)values('"& Format(myDate,"yyyy-mm-dd") &"')"

MyConnection.Execute mStr

Note: You can't use the "#" delimiter in with SQL Server database , but it is OK with MS Access.



0
 

Expert Comment

by:SpideyMod
ID: 7812463
This question was on a cleanup list, but the question has recent activity.  I will leave this one alone.  alhanouty, you are responsible for maintaning your open questions. If you do not get a response back from any of the experts within the next 7 days or so, please post a zero-point question in the Community Support area asking for this to be deleted.  Copy the URL for the question and paste it in the comment section of the deletion request along with what you think should be done.  You have at least one other question that needs a disposition as well, check your profile by clicking any of the links with your name on it.  Thanks.

SpideyMod
Community Support Moderator @Experts Exchange
0
 

Accepted Solution

by:
SpideyMod earned 0 total points
ID: 7895337
PAQ'd and points refunded

SpideyMod
Community Support Moderator @Experts Exchange
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

813 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

12 Experts available now in Live!

Get 1:1 Help Now