This topic is locked

GET THE MONTH AND YEAR VALUE FROM A DATE/TIME FIELD

11/15/2012 6:40:49 AM
PHPRunner General questions
C
chrispa author

Hi,
I have a field named date which is date/time field and user select a date from the calendar .

  1. i need the calendar to show only months and years not dates , is it possibly
  2. i have two more fields 'month' and 'year' and i want after add or edit of field 'date' the fields to get the month and year values only .
    for example if date is Nov 2012

    month to be 10

    year to be 2012
    thanks

C
cgphp 11/15/2012

Could you explain the "only months and years not dates" sentence?

G
gudon 11/15/2012

chrispa, hope I understand your question correctly.
Try these event code in the Before record added page or Before record updated page:
$values["month"]=date("n", strtotime($values["date"]));

$values["year"]=date("Y", strtotime($values["date"]));
change date, month, year to your real field names.
BTW: Do you have a typo in "month to be 10"? Did you mean 11 instead of 10?

C
chrispa author 11/16/2012



chrispa, hope I understand your question correctly.
Try these event code in the Before record added page or Before record updated page:
$values["month"]=date("n", strtotime($values["date"]));

$values["year"]=date("Y", strtotime($values["date"]));
change date, month, year to your real field names.
BTW: Do you have a typo in "month to be 10"? Did you mean 11 instead of 10?


yes typo error sorry
thanks
any idea how to make calendar to show only months and years not dates i.e. Nov 2012 , Dec 2012 etc. ?
thanks

G
gudon 11/16/2012

chrispa,
If you are asking about the "Mon" format, it is:

$Mon=date('M',strtotime($values["date"]));
This will return Jan, Feb, Mar and so on.
Then your desired display would be: $Mon.' '.$year.
====================================================
You can use view as - custom window in the Editor page to do this for your date field:
$Mon=date('M', strtotime($data["date"]));

$year=date('Y', strtotime($data["date"]));
$value=$Mon.' '.$year;