jay-are
asked on
Need to get a "Days Old" working!
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!
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!
Why not use the datediff function
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.
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.
ASKER
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.
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.
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.
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.
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
lblDaysGone = lalalalalala
ASKER
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\ne w\omg2.asp x 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(ConnectionSt ring)
Dim Adapter As SqlDataAdapter = New SqlDataAdapter
Dim Date1 As string
Adapter.SelectCommand = _
New SqlCommand(SelectCommand1, myConnection)
myConnection.Open()
Adapter.Fill(objDataSet,"a ccounting" )
Adapter.SelectCommand = _
New SqlCommand(SelectCommand2, myConnection)
Adapter.Fill(objDataSet,"c omments")
DataGrid1.DataSource = objDataSet.Tables("Account ing")
DataGrid1.Databind()
Date1 = DateDiff("d", Now, objDataSet[Jrnl.Date])
End Sub
Thanks!
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\ne
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(ConnectionSt
Dim Adapter As SqlDataAdapter = New SqlDataAdapter
Dim Date1 As string
Adapter.SelectCommand = _
New SqlCommand(SelectCommand1,
myConnection.Open()
Adapter.Fill(objDataSet,"a
Adapter.SelectCommand = _
New SqlCommand(SelectCommand2,
Adapter.Fill(objDataSet,"c
DataGrid1.DataSource = objDataSet.Tables("Account
DataGrid1.Databind()
Date1 = DateDiff("d", Now, objDataSet[Jrnl.Date])
End Sub
Thanks!
Should there not be an exclamation mark in there after objDataSet ? i.e
Date1 = DateDiff("d", Now, objDataSet![Jrnl.Date])
Date1 = DateDiff("d", Now, objDataSet![Jrnl.Date])
ASKER
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'.
BC30277: Type character '!' does not match declared data type 'System.Data.DataSet'.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks for your help Tom. I'll post this up in the asp section and see what I get.