Hi All

I am currently drawing up a database for contractor management. We have to keep an eye on when these contractors were inducted. The max term of an induction is 1 year. I have built a database and everything works EXCEPT when I want it to calculate the number of months between the date of their induction (from an access db file) and todays date. I get an error message indicating that the access db date cannot be converted.

Can anyone please advise me on how to overcome this problem?

Regards

Rod

Date needs to be in yyyyMMdd format

Dim theDate as DateTime = #02/02/2005#

Dim ymd As String = theDate.ToString("yyyyMMdd")

If this isn't the problem you are facing please clarify I am not sure what you want.

Hi Finito

Here is my code. I still get the same error.

Regards

Rod

[

Public Class Form1

    Private Sub Table1BindingNavigatorSaveItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Table1BindingNavigatorSaveItem.Click
        Me.Validate()
        Me.Table1BindingSource.EndEdit()
        Me.TableAdapterManager.UpdateAll(Me.DataSet1)

    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'TODO: This line of code loads data into the 'DataSet1.Table1' table. You can move, or remove it, as needed.
        Me.Table1TableAdapter.Fill(Me.DataSet1.Table1)

    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim thedate As DateTime = #3/2/2005#
        Dim ymd As String = thedate.tostring("yyyymmdd")
        If DateDiff(DateInterval.Month, InductedDateTimePicker, Today) > 12 Then
            label1.visible = True

        End If
    End Sub
End Class

]

Dim thedate As DateTime = #3/2/2005#
Dim ymd As String = thedate.tostring("yyyymmdd")

This is sample code.

Where is the problem you are having, and please use code tagging.

Sorry about code tagging I am still learning the drill.

The error I get when running the program is...

Argument 'Date1' cannot be converted to type 'Date'.

Date1 refers to the date drawn from MS access. It appears - to my limited knowledge that is, that the two dates are not similar. For instance, todays date might be yyyymmdd and the one from the database may be ddmmyyyy and the computer may be unable to interpret it. By the way I have checked my regional settings to ensure that the date for today is in the short date format.

Where is Date1?

Try this when you get Date from Access.

DateTime.Parse(Date1.ToString()).CompareTo(DateTime.Now)

you will get int result for this
0 means equal -1 means less than 1 is greater than

if you show me your code where you are comparing I can help you greater.

Appreciate your assistance by the way!!

Could I please try another code to simplify things.

1) I set up a basic Access DB with a single (date/time)field called Datee
2) I draw up a simple VB DB program (attached) that has the following:
(a) a button loaded with code
(b) a datetimepicker in which I have to select a date
(c) a text box in which I want to display the date selected in (b) above and
(d) a textbox displaying todays date

In doing this I am attempting to get the two dates displayed in the textboxes to display the selected date from the DTPbox in the one and todays date in the other. Should you run this program you will see that I land up with a problematic date in one. To get my program to work, I need to have these two dates displaying correctly as I will be using datediff to calculate the difference in the number of months between the two dates.

Running the program you will motice that once the button is pressed I get complete gobbledegook in the textbox that ought to display the date in the datetimepickerbox.

I do not know how to upload the Access DB I created. Should I know I would have done so.

Regards

Rod

Public Class Form1

    Private Sub Table1BindingNavigatorSaveItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Table1BindingNavigatorSaveItem.Click
        Me.Validate()
        Me.Table1BindingSource.EndEdit()
        Me.TableAdapterManager.UpdateAll(Me.DataSet1)

    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'TODO: This line of code loads data into the 'DataSet1.Table1' table. You can move, or remove it, as needed.
        Me.Table1TableAdapter.Fill(Me.DataSet1.Table1)

    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
       
        Dim dateedatetimepicker As DateTime = #2/2/2010#
        Dim ymd As String = dateedatetimepicker.ToString("yyyy/mm/dd")
        TextBox1.Text = ymd

        TextBox2.Text = Today


    End Sub
End Class

Thank you for your assistance.

Rod

please mark as solved if solved.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.