Results 1 to 9 of 9

Thread: SQL Server date...help!

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2004
    Location
    Utah, USA
    Posts
    353

    SQL Server date...help!

    I have a question. If I have a date in a textbox, but then delete it so it is blank. Then I update (save) it. When I open my form again and open that record, the date shows up like this: 1/1/1900

    Why is that?

  2. #2
    Big D Danial's Avatar
    Join Date
    Jul 2000
    Location
    ASP.Net Forum
    Posts
    2,877

    Re: SQL Server date...help!

    Originally posted by brendalisalowe
    I have a question. If I have a date in a textbox, but then delete it so it is blank. Then I update (save) it. When I open my form again and open that record, the date shows up like this: 1/1/1900

    Why is that?
    How are you passing the Date, in VB when you declare a variable as date, it assigns a intial value of 1/1/1900 so i think thats whats happening.

    When you update it try passing Null. How are you updating, stored procedure or Front end SQL Query, also what Database are you using?
    [VBF RSS Feed]

    There is a great war coming. Are you sure you are on the right side? Atleast I have chosen a side.

    If I have been helpful, Please Rate my Post. Thanks.

    This post was powered by :

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2004
    Location
    Utah, USA
    Posts
    353
    I am updating using Front End SQL and SQL Server. What should I do different?

  4. #4
    Big D Danial's Avatar
    Join Date
    Jul 2000
    Location
    ASP.Net Forum
    Posts
    2,877
    Originally posted by brendalisalowe
    I am updating using Front End SQL and SQL Server. What should I do different?
    Have you tried passing null value? See if that works and let me know.
    [VBF RSS Feed]

    There is a great war coming. Are you sure you are on the right side? Atleast I have chosen a side.

    If I have been helpful, Please Rate my Post. Thanks.

    This post was powered by :

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2004
    Location
    Utah, USA
    Posts
    353
    But how do you pass a null value? All I did was delete the value I had in the textbox so it was blank. Is there a better way to go about it?

  6. #6
    Big D Danial's Avatar
    Join Date
    Jul 2000
    Location
    ASP.Net Forum
    Posts
    2,877
    Originally posted by brendalisalowe
    But how do you pass a null value? All I did was delete the value I had in the textbox so it was blank. Is there a better way to go about it?
    e.g
    if txtMyDate.text ="" then
    sql= "Update MyTable set MyDate=null Where ID=" & ID

    Conn.execute (sql)
    end if
    [VBF RSS Feed]

    There is a great war coming. Are you sure you are on the right side? Atleast I have chosen a side.

    If I have been helpful, Please Rate my Post. Thanks.

    This post was powered by :

  7. #7
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687
    No Date = 1/1/1900
    Null Date = 12/31/1899

    This "arguement" has been hashed to deal more than once in these forums. It's the way MS decided to deal with such dates. Not sure why, but in theory, it's because you can't not have a date, the date "has to exist" it would be like not having time.... but that gets into exestencialism and other etherial thinking.

    TG
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  8. #8
    Fanatic Member vb_dba's Avatar
    Join Date
    Jun 2001
    Location
    Somewhere aloft between the real world and insanity
    Posts
    1,016
    In my ASP pages, I intentionally set my date values to '01/01/1900' if the user didn't enter the date. When I perform my select statement I check if the date = '01/01/1900' and just return an empty string if it does since this is not a date we would use here to signify anything:
    Code:
    Select Case When myDate = '01/01/1900' Then ''
                        When myDate Is Null Then ''
                        Else Convert(varchar(10), myDate, 101) End'myDate'
    From myTable
    Where ID = @ID
    If you consider doing it this way, you MUST convert the date to a character field (varchar, char), otherwise it will still return '01/01/1900'.
    Chris

    Master Of My Domain
    Got A Question? Look Here First

  9. #9

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2004
    Location
    Utah, USA
    Posts
    353
    Thanks! It works perfect!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width