nkt
Založený: 16.05.2008
Príspevky: 14
Zaslal: 2008-05-24 01:39
Návrat hore
Odpovedať s citátom
|
$opts['fdd']['Date'] = array(
'name' => 'Date',
'select' => 'T',
'maxlen' => 10,
'options' => 'AFCPVD',
'required' => true,
'default|sql' => 'CURDATE()',
'help' => '<== Please click on Calendar to select the Date',
'calendar' => array(
'showsTime' => 'false',
'button' => 'true',
'label' => 'Calendar'
),
'sort' => true
);
|
ajh
Založený: 17.12.2003
Príspevky: 236
Zaslal: 2008-05-27 20:47
Návrat hore
Odpovedať s citátom
|
Try the following:
| Kód: |
$opts['fdd']['Date'] = array(
'name' => 'Date',
'select' => 'T',
'maxlen' => 10,
'options' => 'AFCPVD',
'required' => true,
'sql|A' => 'CURDATE()',
'help' => '<== Please click on Calendar to select the Date',
'calendar' => array(
'showsTime' => 'false',
'button' => 'true',
'label' => 'Calendar'
),
'sort' => true
); |
|
Icehawg
Založený: 09.04.2008
Príspevky: 20
Zaslal: 2008-05-29 02:10
Návrat hore
Odpovedať s citátom
|
Just a suggestion but wouldn't it be better to use SQL only where necessary and PHP where it's best suited?
| Kód: |
| 'default' => date("Y/m/d H:i:s", strtotime("now")), |
|
ajh
Založený: 17.12.2003
Príspevky: 236
Zaslal: 2008-05-29 14:49
Návrat hore
Odpovedať s citátom
|
Sure...when I first started doing this, php wasn't an option.
|
nkt
Založený: 16.05.2008
Príspevky: 14
Zaslal: 2008-06-05 19:42
Návrat hore
Odpovedať s citátom
|
Thanks,
that works. I also want to add the current_date option when I copy the record or change the record.
In copy can we overwrite the date value with current date value?
|
ajh
Založený: 17.12.2003
Príspevky: 236
Zaslal: 2008-06-06 09:13
Návrat hore
Odpovedať s citátom
|
The best way of doing this is to use the SQL option:
| Kód: |
| 'sqlw' => 'CURDATE()' |
This will always write the current date into the field when the record is updated.
|
Icehawg
Založený: 09.04.2008
Príspevky: 20
Zaslal: 2008-06-06 12:54
Návrat hore
Odpovedať s citátom
|
It really depends on what returned value you would like in your table. If you want to return the current date as a value in 'YYYY-MM-DD' or YYYYMMDD format then use the proper code as ajh suggested to you already.
However if you want to return a Unix timestamp (seconds since '1970-01-01 00:00:00' UTC) then you should probably use the following code :
| Kód: |
| 'sqlw' => 'UNIX_TIMESTAMP()' |
|
ajh
Založený: 17.12.2003
Príspevky: 236
Zaslal: 2008-06-06 12:59
Návrat hore
Odpovedať s citátom
|
If you are storing the field into a MySQL DATE type field, then you need to use the CURDATE format otherwise MySQL will misinterpret it. If it is a text field then it doesn't matter.
|
|
Odoslať novú tému
Odpovedať na tému
|