damian
Posts: 838
|
| Posted: 03/24/2011, 3:10 PM |
|
i have a news post section and have just added a new date field - message_archive
on/after the specified date the news item will move from current/active news section to archive section. thats all fine.
im having trouble setting a default value for this field. i want news to move after 1 week by default but the poster may require it to be there for shorter or longer.
im using following code to set archive date:
if ($Component->GetValue() == '') $Component->SetValue(date('d/m/Y', strtotime('+1 week')));
code gives desired output eg 01/04/2011 in a text field but as soon as i change it to date field it reverts to 01/01/1970
i cant see what im missing - my global date settings are good as all other date fields work. i have set format to dd/mm/yyyy and dbformat to yyyy-mm-dd HH:nn:ss
again this is the same as all my other date fields. if i use date picker to stick the date in it is recorded and displays correctly but my code seems to supply something that my ccs settings wont read properly.
_________________
if you found this post useful take the time to help someone else.... :)
|
 |
 |
damian
Posts: 838
|
| Posted: 03/24/2011, 3:13 PM |
|
oh - i also tried:
if ($Component->GetValue() == '') $Component->SetValue(date('Y-m-d', strtotime('+1 week')));
as that is the format i see when i look in the db itself but i get same result 01/01/1970
_________________
if you found this post useful take the time to help someone else.... :)
|
 |
 |
ckroon
Posts: 869
|
| Posted: 03/24/2011, 5:37 PM |
|
lately I have been a big fan of setting the DB date field to Varchar and working with the yyyy-mm-dd format in the code
_________________
Walter Kempees...you are dearly missed. |
 |
 |
datadoit
|
| Posted: 03/24/2011, 6:15 PM |
|
The field is text in the database. When you set the display on your
grid or form to Date, all that does is parse and format the text data in
the background to the format that you want.
You need to do the same thing in custom coding if you want to alter the
value of the field. So CCParseDate() and CCFormatDate() when you set
it, if the format you're setting does not match the format specified for
the display field.
|
|
|
 |
damian
Posts: 838
|
| Posted: 03/24/2011, 10:37 PM |
|
hi data - i have set the database field as date - it is not a varchar field?
i did read the help file on CCParseDate and CCFormatDate and hoped i didnt need to do that... i will have another look.
hi ckroon - its tempting sometimes...
_________________
if you found this post useful take the time to help someone else.... :)
|
 |
 |
datadoit
|
| Posted: 03/25/2011, 5:14 AM |
|
The only way to avoid CCFormatDate() and CCParseDate() in your situation
is to set the date format to match the database format when you set the
value.
$Component->SetValue(date('Y-m-d H:i:s', strtotime('+1 week')))
Now the value will be in the format that matches the database, and CCS
will subsequently format the display field to the way you want.
|
|
|
 |
Waspman
Posts: 948
|
| Posted: 03/26/2011, 7:26 AM |
|
I did a similar thing. I didn't store an expiry date just the number of days it would expire in. The user could set the expiry number or it would default to a global setting or a setting for that user. Then you could show/archive the data based on a simple sum. You could let them put a date in count the difference between now and them and store the number. I'm sure I did something like that too. :)
_________________
http://www.waspmedia.co.uk |
 |
 |