Subject Re: date conversion for mysql
From Mervyn Bick <invalid@invalid.invald>
Date Thu, 10 Jan 2019 12:16:33 +0200
Newsgroups dbase.getting-started

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.