Subject |
Re: date conversion for mysql |
From |
Charlie <tm@tc.com> |
Date |
Thu, 10 Jan 2019 22:57:19 -0500 |
Newsgroups |
dbase.getting-started |
Hi Mervyn... Thanks.. I'll try that. I came up with one for xdml although it isn't tested. Think this will work?
datestring = dtos(date())
yearstr = year(date())
monthstr = month(date())
if monthstr < 10
monthstr = "0"+ monthstr
endif
daystr = day(date())
if daystr < 10
daystr = "0" + daystr
endif
datestring = "'"+yearstr+"-"+monthstr+"-"+daystr+"'"
msgbox( datestring )
Mervyn Bick Wrote:
> On 2019-01-10 11:36 AM, Charlie wrote:
> > Hi.. Is there an easy way to convert a date field to this format?
> >
> > It could be a character string result also.....
> >
> > yyyy-mm-dd
> >
> > I believe the dashes have to be there....
> >
> > Thanks much for any help!
> >
>
> The following little function will convert a date to a string in the
> format that MYSQL wants. Remember that you need to wrap the string in
> quotes if you are going to use it in a SQL statement.
>
> If you want the string "Pre-wrapped" change the last line of the
> function to
>
> return "'"+yr+'-'+mn+'-'+da+"'"
>
> ? date2mysql(date())
>
> function date2mysql(date)
> //accepts a date, returns a string
> yr = date.year
> mn = str(date.month+1,2,0,'0')
> da = str(date.date,2,0,'0')
> return yr+'-'+mn+'-'+da
>
>
> Mervyn.
|
|