Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 168
  • Last Modified:

Date Formatting again q

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
alhanouty
Asked:
alhanouty
  • 4
  • 4
  • 2
  • +3
1 Solution
 
ProgramITCommented:
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
 
aikimarkCommented:
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
 
Anthony PerkinsCommented:
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
DanRollinsCommented:
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
 
alhanoutyAuthor Commented:
Yes I disagree, because non of the above comments solve my problem, so Iam going to delete the question.
0
 
aikimarkCommented:
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
 
alhanoutyAuthor Commented:
Ok..

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

thats all

0
 
DanRollinsCommented:
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
 
aikimarkCommented:
I don't get the points, but I agree with DanRollins.
0
 
alhanoutyAuthor Commented:
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
 
aikimarkCommented:
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
 
alhanoutyAuthor Commented:

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
 
SpideyModCommented:
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
 
SpideyModCommented:
PAQ'd and points refunded

SpideyMod
Community Support Moderator @Experts Exchange
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 4
  • 4
  • 2
  • +3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now