Solved

Date Formatting again q

Posted on 2002-04-14
14
158 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
 
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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
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 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…
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…

705 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

21 Experts available now in Live!

Get 1:1 Help Now