Gossamer Forum
Home : Products : DBMan SQL : Discussion :

Default to current date

Quote Reply
Default to current date
Hello,

How do I get a column defined as a type 'DATE' to default to the current date just like in dbman so that whenever I add a record the Date field defaults to today's date. Keep in mind this is within the context of using the db.cfg and nph-setup.cgi that comes with dbsql.

In my cfg file I've tried now(), curdate(), etc. for the default value for field Date but none of these have worked for me. Any insights or suggestions would be most appreciated.


easy does it
Quote Reply
Re: Default to current date In reply to
In Reply To:
How do I get a column defined as a type 'DATE' to default to the current date just like
Never mind, I figured it out.


easy does it
Quote Reply
Re: Default to current date In reply to
For the benefit of others, you might want to post the fix in this Thread...oh wait a minute...I forgot who I am replying to...that is not you at all...sorry. Tongue

Regards,

Eliot Lee

Quote Reply
Re: Default to current date In reply to
How did you get the date to work? I just get 0's

----------------
donm

Quote Reply
Re: Default to current date In reply to
In Reply To:
How did you get the date to work? I just get 0's
In your cfg file where you've defined a FIELD TYPE as DATE use 'now' as the default value.

hth

easy does it
Quote Reply
Re: Default to current date In reply to
Hello,

when i put 'now' on the date field, it works only for a new record, but the rest of the records (the one that I just imported from flat text), appears to be 0s.

anyone has any experience about this?

__________________________
SantanaBlank
Quote Reply
Re: Default to current date In reply to
In Reply To:
when i put 'now' on the date field, it works only for a new record, but the rest of the records (the one that I just imported from flat text), appears to be 0s.
Most likely because the existing dates in your flat-file don't conform to the mySQL DATE format which is YYYY-MM-DD

If you only have a few records in your flat-file it is simple enough to manually change them to the proper format before you import into mySQL table. If not then you'll have to pull your flat-file into something like Access, reformat the date field, then export back out to a flat-file, then import into mySQL.

HTH

easy does it
Quote Reply
Re: Default to current date In reply to
In Reply To:
Most likely because the existing dates in your flat-file don't conform to the mySQL DATE format which is YYYY-MM-DD
Well, i have changed the format to yyyy-mmm-dd (it was reformated by excel, and saved as txt)
but when I import it into mySQL, they just changed to 0s.
But, When I changed the field in mySQL into TEXT before the import, then it shows correctly.

I tried to changed the field in mySQL to 'DATE' then it shows 0s again.

thanks for replying :)


__________________________
SantanaBlank
Quote Reply
Re: Default to current date In reply to
In Reply To:
Well, i have changed the format to yyyy-mmm-dd
Well that is still wrong...mySQL stores a DATE type field as YYYY-MM-DD

You need to do the same to properly import the file.


easy does it
Quote Reply
Re: Default to current date In reply to
Aha...
Yes, I was wrong.
Now it is working :)

thanks

__________________________
SantanaBlank