This topic is locked
[SOLVED]

 Month and Year from datefield?

9/20/2012 7:31:47 AM
PHPRunner General questions
P
punch author

Hello,
we have three fields in our database: mydate, mymonth, myyear.

Users can edit any date in the field "mydate" (not even the actual date, i.e. a date in the future).

Now we wish to fill month and year of the date, which was edited, automatically into the fields "mymonth" and "mydate".
We know, that we should use the "after record added"-event, but we do not know, how to write the code snippet.
We guess, is it something like
$mymonth= month($mydate)

$myyear= year($mydate)
but this snippet does not work (as we expected).
Best regards
Punch

C
cgphp 9/20/2012
Sergey Kornilov admin 9/20/2012

Check PHP date() function:

http://php.net/manual/en/function.date.php

$mymonth = date("n",strtotime($mydate))

$myyear = year("Y",strtotime ($mydate))
P
punch author 11/16/2012

Hello,
we tried the following version
$termin_monat = date("n",strtotime($termin_datum_von));

$termin_jahr = date("Y",strtotime ($termin_datum_von));

exit();
but we get an error.
Same with
$termin_monat = date("n",strtotime($termin_datum_von));

$termin_jahr = year("Y",strtotime ($termin_datum_von));

exit();
Patrick

Sergey Kornilov admin 11/16/2012

Patrick,
make sure that $termin_datum_von variable is defined and has correct date value in it.

P
punch author 11/19/2012

Hi,
i found the error:

If the code is placed in the event "BeforeAdd" it works ("AfterAdd" was the wrong place for the function.
Punch