?
Solved

Need to get a "Days Old" working!

Posted on 2003-11-12
10
Medium Priority
?
235 Views
Last Modified: 2010-05-01
Hello Experts!

I'm using a datagrid to show information.  It's data comes from a few sql tables.  One table contains JRNL.DATE.  It shows its type as 'smalldatetime'.  It's formatted like this:  YYYY-MM-DD  TT:TT:TT

I need some help calculating how old each record is based on today's date.  

Do I need to go this route:
http://www.planet-source-code.com/vb/scripts/ShowCode.asp?lngWId=1&txtCodeId=2900

or is there something easier?
This will be used in an asp.net page.
help!
0
Comment
Question by:jay-are
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
10 Comments
 
LVL 4

Expert Comment

by:TomLaw1999
ID: 9733954
Why not use the datediff function

0
 
LVL 4

Expert Comment

by:TomLaw1999
ID: 9733972
Example as given in MSDN

Dim TheDate As Date   ' Declare variables.
Dim Msg
TheDate = InputBox("Enter a date")
Msg = "Days from today: " & DateDiff("d", Now, TheDate)
MsgBox Msg

Jut substitute your stored date for 'TheDate' and you have your value.
0
 

Author Comment

by:jay-are
ID: 9734474
TomLaw:

So it should look something like this?

DateDiff("d", Now, [Jrnl.Date])?

I'm a noob to VB so you'll have to excuse my ignorance.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 4

Expert Comment

by:TomLaw1999
ID: 9738184
Hi Jay

Yes you're on the right lines, if you are extracting the date from a recordset value you may also need to enter the recordset name e.g.

MyValue = DateDiff("d", Now, Recordsetname![Jrnl.Date])

This should return the difference in days between the two dates.
0
 
LVL 2

Expert Comment

by:cofneverlivetotell
ID: 9739326
Use the sys clock to get the time when (installed i guess) and keep it in an ini file or something, then get the program to refer to it and the sysclock to see how many days there are, put this in teh app in something like

lblDaysGone = lalalalalala
0
 

Author Comment

by:jay-are
ID: 9739752
TomLaw:

I'm trying to use this in a datagrid.  I just need to display the days between each records date and today.  It actually needs to be done for every  control number in the dataset.  I've included my code here.  It gives me the error:
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: BC30203: Identifier expected.

Source Error:

 

Line 283:
Line 284:                   DataGrid1.Databind()
Line 285:                   Date1 = DateDiff("d", Now, objDataSet[Jrnl.Date])
Line 286:          End Sub
Line 287:
 

Source File: c:\inetpub\wwwroot\aspx\new\omg2.aspx    Line: 285

Can you help me get this working right with my code here?

Sub BindGrid()
                   Dim objRelation As DataRelation
                   Dim objDataSet As DataSet = New DataSet
                   Dim myConnection As New SqlConnection(ConnectionString)
                   Dim Adapter As SqlDataAdapter = New SqlDataAdapter
                   Dim Date1 As string


                   Adapter.SelectCommand = _
                       New SqlCommand(SelectCommand1, myConnection)
                       myConnection.Open()
                      Adapter.Fill(objDataSet,"accounting")

                      Adapter.SelectCommand = _
                       New SqlCommand(SelectCommand2, myConnection)
                       Adapter.Fill(objDataSet,"comments")


                   DataGrid1.DataSource = objDataSet.Tables("Accounting")

                   DataGrid1.Databind()
                   Date1 = DateDiff("d", Now, objDataSet[Jrnl.Date])
          End Sub

Thanks!

0
 
LVL 4

Expert Comment

by:TomLaw1999
ID: 9740592
Should there not be an exclamation mark in there after objDataSet ? i.e

Date1 = DateDiff("d", Now, objDataSet![Jrnl.Date])
0
 

Author Comment

by:jay-are
ID: 9740634
I tried having the '!' after the objDataSet but it gives me this error:
 BC30277: Type character '!' does not match declared data type 'System.Data.DataSet'.
0
 
LVL 4

Accepted Solution

by:
TomLaw1999 earned 1000 total points
ID: 9740801
Sorry jay I am confident enough about datediff handling the calculation but I am a bit shaky with datasets. You will need to work out how to extract the date information then use it in the datediff function.
0
 

Author Comment

by:jay-are
ID: 9740835
Thanks for your help Tom.  I'll post this up in the asp section and see what I get.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
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.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
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…
Suggested Courses

650 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