Results 1 to 16 of 16

Thread: [RESOLVED] Vb-Sql 2000 Date format Problem in query

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jul 2013
    Posts
    66

    Resolved [RESOLVED] Vb-Sql 2000 Date format Problem in query

    I am using vb6 for developing my database application for storing and displaying data. The Problem is the date format in different computers using my application. The Client has different computers where date format differ like 'mm/dd/yyyy' and 'dd/mm/yyyy'. When inserting and displaying data, the server takes date as its regional settings which is different from node's. That is when node sends '09/10/2013' (the 09 is day) the server stores it as sep- 10 -2013. Also when displaying data the server misinterprets the node's request and sends wrong data.I cannot change their date formats using my application. (Its Their Settings)
    Is there any way to send datetime as double and decode it in server? Any Fix? Thank You.
    I searched many threads but did not find answer suitable for me. I don't know if this is the right forum to post. But I am using vb6.

  2. #2
    Addicted Member ryanframes's Avatar
    Join Date
    Apr 2012
    Posts
    210

    Re: Vb-Sql 2000 Date format Problem in query

    use format 'yyyy-mm-dd' when updating the database.
    Sorry for bad english.

  3. #3
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,537

    Re: Vb-Sql 2000 Date format Problem in query

    Depends... how are you sending the dates to the database? PArameters or are you concatenatiing strings together? If you use parameters, it should make the problem go away. should.

    -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??? *

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Jul 2013
    Posts
    66

    Re: Vb-Sql 2000 Date format Problem in query

    When Updating I Try To Use Procedures. But When displaying Reports, the query is string and I am using recordset. Are you saying that I don't have to worry when I am using parameters?

  5. #5
    Addicted Member ryanframes's Avatar
    Join Date
    Apr 2012
    Posts
    210

    Re: Vb-Sql 2000 Date format Problem in query

    so when updating , is the date format still in the client's regional setting ?
    also, what component that you use to display the reports ?
    Sorry for bad english.

  6. #6
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: Vb-Sql 2000 Date format Problem in query

    Quote Originally Posted by BlueFox View Post
    Are you saying that I don't have to worry when I am using parameters?
    As soon as you turn your "data value" into a STRING you lose control over the fact that it was a date.

    Parameters can accept DATETIME datatypes - so the "data value" never goes into the "evil" string world.

    If you are going to make an UPDATE and use a non-parameter method - thus a STRING is involved - you best make it YYYY-MM-DD at that moment so you can avoid regional setting problems.

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Jul 2013
    Posts
    66

    Re: Vb-Sql 2000 Date format Problem in query

    I don't think, while using the parameters, I ever got wrong date. The problem was while building query for report, I embed the date into the query string from the date picker. Some records are missing. Like november 10 becomes october 11 in select query. Its not the problem of component. Its that I don't get all the data into the recordset from database while using between etc.

  8. #8
    Addicted Member ryanframes's Avatar
    Join Date
    Apr 2012
    Posts
    210

    Re: Vb-Sql 2000 Date format Problem in query

    can you show us your query ?
    Sorry for bad english.

  9. #9
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,537

    Re: Vb-Sql 2000 Date format Problem in query

    Quote Originally Posted by BlueFox View Post
    I don't think, while using the parameters, I ever got wrong date. The problem was while building query for report, I embed the date into the query string from the date picker. Some records are missing. Like november 10 becomes october 11 in select query. Its not the problem of component. Its that I don't get all the data into the recordset from database while using between etc.
    because you're converting it into a string for your query... that's what we're trying to tell you... if you used parameters in the query, it shouldn't be a problem... it sounds like you're not... and as a result, some dates are being misinterpreted (likely your passed in dates to the where clause).

    -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??? *

  10. #10

    Thread Starter
    Lively Member
    Join Date
    Jul 2013
    Posts
    66

    Re: Vb-Sql 2000 Date format Problem in query

    While Clicking Search Button On Server This is the query being generated:
    select * from admission where deleted=0 and dob between '12/09/2013' and '12/11/2013'
    But the same search button generates this on node:
    select * from admission where deleted=0 and dob between '09/12/2013' and '11/12/2013'
    Therefore Results Differ.
    I am going to Change It To Procedure/'Parameterized' Queries. Th.Yu.

    Here is the code I am going to use
    Dim sqlCmd As ADODB.Command
    Set sqlCmd = New ADODB.Command
    sqlCmd.ActiveConnection = Ycnn
    sqlCmd.CommandType = adCmdStoredProc
    sqlCmd.CommandText = "proDisplayHolidays"
    sqlCmd.Parameters("@holidayfrom") = dtpFrom.value
    sqlCmd.Parameters("@holidayto") = dtpTo.value

    sqlcmd.execute 'Catch the results in recordset

    Will this be enough?
    Last edited by BlueFox; Dec 12th, 2013 at 12:21 AM.

  11. #11
    Addicted Member ryanframes's Avatar
    Join Date
    Apr 2012
    Posts
    210

    Re: Vb-Sql 2000 Date format Problem in query

    Code:
    sqlCmd.Parameters("@holidayfrom") = dtpFrom.value
    sqlCmd.Parameters("@holidayto") = dtpTo.value
    assuming that on your stored procedure the parameters data type's datetime, so when store the parameters use format 'yyyy-mm-dd' like this :
    Code:
    sqlCmd.Parameters("@holidayfrom") = Format(dtpFrom.value,"yyyy-mm-dd")
    sqlCmd.Parameters("@holidayto") = Format(dtpTo.value,"yyyy-mm-dd")
    Sorry for bad english.

  12. #12
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: Vb-Sql 2000 Date format Problem in query

    Er, now we're back to formatting dates as String values and relying on implicit coercion again.

  13. #13

    Thread Starter
    Lively Member
    Join Date
    Jul 2013
    Posts
    66

    Re: Vb-Sql 2000 Date format Problem in query

    Quote Originally Posted by dilettante View Post
    Er, now we're back to formatting dates as String values and relying on implicit coercion again.
    So Should I omit Format Function?

  14. #14
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,537

    Re: Vb-Sql 2000 Date format Problem in query

    You should be using parameters properly and not formatting a thing...

    -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??? *

  15. #15
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: Vb-Sql 2000 Date format Problem in query

    Quote Originally Posted by szlamany View Post
    As soon as you turn your "data value" into a STRING you lose control over the fact that it was a date.

    Parameters can accept DATETIME datatypes - so the "data value" never goes into the "evil" string world.

    If you are going to make an UPDATE and use a non-parameter method - thus a STRING is involved - you best make it YYYY-MM-DD at that moment so you can avoid regional setting problems.
    I am guessing this post did not make sense?

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  16. #16

    Thread Starter
    Lively Member
    Join Date
    Jul 2013
    Posts
    66

    Re: Vb-Sql 2000 Date format Problem in query

    Parameters Then!!.

Tags for this Thread

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