hi..I'm just a newbie programmer who needs some help. I'm trying to enter a date and save it in a mysql database. however the format in mysql is yyyy-mm-dd and the format in vb.net is mm-dd-yyyy. how can i format the date in vb in order to successfully enter it in the database?

ive tried using this code

dim mydate as string
mydate = now.year & "-" & now.month & "-".now.day

and it works but the problem is I'm trying to use the date in order to get the difference
between two given months using the DateDiff function but it wont accept it since the variable mydate is a string and not a date type
how can I fix this problem? thanks

hi..I'm just a newbie programmer who needs some help. I'm trying to enter a date and save it in a mysql database. however the format in mysql is yyyy-mm-dd and the format in vb.net is mm-dd-yyyy. how can i format the date in vb in order to successfully enter it in the database?

ive tried using this code

dim mydate as string
mydate = now.year & "-" & now.month & "-".now.day

and it works but the problem is I'm trying to use the date in order to get the difference
between two given months using the DateDiff function but it wont accept it since the variable mydate is a string and not a date type
how can I fix this problem? thanks

dim mydate as string
mydate =Format(Now,"yyyy-MM-dd")

hi..I'm just a newbie programmer who needs some help. I'm trying to enter a date and save it in a mysql database. however the format in mysql is yyyy-mm-dd and the format in vb.net is mm-dd-yyyy. how can i format the date in vb in order to successfully enter it in the database?

ive tried using this code

dim mydate as string
mydate = now.year & "-" & now.month & "-".now.day

and it works but the problem is I'm trying to use the date in order to get the difference
between two given months using the DateDiff function but it wont accept it since the variable mydate is a string and not a date type
how can I fix this problem? thanks

First, store your date as Date/Time in your Database

row("mydate") = Format(Now, "General Date") 'mydate is a Date/Time Format in your MySQL Database

Then get Them and place it in your variable like below

Dim date1 As Date
Dim date2 As Date

Me.Textbox1.Text = DateDiff(DateInterval.Day, Date1,Date2)
This article has been dead for over six months. Start a new discussion instead.