Link to home
Start Free TrialLog in
Avatar of maqskywalker
maqskywalker

asked on

convert datetime to date

I'm using VB.NET in ASP Web Forms.

I have a button click like this:

    Protected Sub Button1_Click(sender As Object, e As EventArgs)

        Dim DateTimeVar1 As DateTime
        DateTimeVar1 = "10/31/2018 01:05:00 PM"

        'Set Label With Variable Value
        Label1.Text = DateTimeVar1

    End Sub

How do I convert the DateTime variable DateTimeVar1 to a Date variable called DateTimeVar2 ?

So then the value stored in DateTimeVar2 should be: 10/31/2018
Avatar of Sam Jacobs
Sam Jacobs
Flag of United States of America image

A Date variable also contains a time component.
If you want to put it into a label, you should use:
 Label1.Text  = Format(DateTimeVar1, "MM/dd/yyyy")

Open in new window

Avatar of maqskywalker
maqskywalker

ASKER

Is there a way to remove the time part off the date variable.

See I need pass this date variable to a stored procedure parameter but the parameter needs to be fed only the date part like this: "10/31/2018"

Currently  it's being fed "10/31/2018 12:49:00 PM"
Even if you stripped off the time component, if you pass it as a Date, you will actually be passing it as "10/31/2018 00:00:00 AM".
Can it be passed as a string?
ASKER CERTIFIED SOLUTION
Avatar of Sam Jacobs
Sam Jacobs
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
thanks worked great.