954,517 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

how to convert date to mysql format

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

herms14
Light Poster
47 posts since Mar 2008
Reputation Points: 10
Solved Threads: 0
 

You should use datetime type variables instead of strings.

martonx
Junior Poster in Training
51 posts since May 2008
Reputation Points: 10
Solved Threads: 8
 

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")

tmani_85
Newbie Poster
14 posts since Feb 2009
Reputation Points: 10
Solved Threads: 2
 

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)
c0deFr3aK
Junior Poster in Training
71 posts since Mar 2009
Reputation Points: 11
Solved Threads: 10
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You