how to get details from two different dates

  • 13 years ago

    i hv a table named jobrequest in sql databse...i'm using two different date to retrieve details...is there any ways to get data by providing two diff date.....the dates will be stored in a same filed.....

    for example:

    column name:getdate, id

    getdate fields   1) 1/10/07                id fields:    1) A1

                           2)2/10/08                                  2) A2

                            3)8/11/2008                              3)A3

    so hw to get the details between two dates.....

    front end = vb.net

    back end = sql server 2000

     

  • 13 years ago

    I suppose it depends where you want to handle the date manipulation.
    1. Manipulate from sql, eg:
    DATEDIFF(day, '10/10/2000', '12/10/2000')

    Will return the amount of days between the two dates, you can choose any date/time modifier in the first parameter, day, hour, month, etc. You can also use other sql date manipulation functions, or create a function of your own to create specifics. You generally have to convert a date to string, but you don't have to convert a string to date; just as long as its syntactically correct.
    2. Manipulate from vbnet:
    This requires manipulating DATE objects, and if you want the same functionality, using a TIMESPAN object: eg,
    Private d1 As Date = #10/10/2000#
    Private d2 As Date = #12/10/2000#
    Sub
    Dim ts As TimeSpan
    ts = d2.Subtract(d1)
    Dim str As String = ts.TotalDays.ToString()

    There are other useful timespan properties and methods. You should be aware however, unless you changed the datetime specific to your region on the database, the result will be month/day/year. This really screwed with my head until I realised it. This is'nt a problem with vb as it converts the date from the server. So it depends, server = less code but more overhead, vb = vice versa.

Post a reply

Enter your message below

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Computer science education cannot make anybody an expert programmer any more than studying brushes and pigment can make somebody an expert painter” - Eric Raymond