Page 1 of 1

format date

PostPosted: Fri Jul 23, 2010 8:16 am
by savefilez
Hello, i'm trying to display the US format mm/dd/yy into text box using the code at http://forum.ajaxavailabilitycalendar.com/viewtopic.php?f=22&t=274 but it keeps putting year/month/day as input.. anyone know how to format the date? thanks. :(

Re: format date

PostPosted: Fri Jul 23, 2010 8:56 am
by chris
Hi,
You would need to modify the JavaScript function so tha it splits the date up into parts and then create a new var with the date parts in the order that you want them.
Something like this:
Code: Select all
function activate_dates(){
  var dateStart=document.id('date');
  $$('li.clickable').each(function(el){
    if(!el.hasClass('booked')){
      el.addEvent('click',function(){
        var dateParts=this.id.split('-');     
        var dateFormat=dateParts[1]+'-'+dateParts[2]+''-'+dateParts[0];
        dateStart.set('value',dateFormat);
      }).setStyle('cursor','pointer');
    }
  })
}

Note - I have not tested this code.

Hope that points you in the right direction ;)

Chris

Re: format date

PostPosted: Mon Jan 31, 2011 6:40 pm
by 69developer
I am wanting so when you hover over calendar date, it will display mm/dd/year.

I tried the above code, but it still shows the date format as 31/1/2011.

I tried different numbers in the dateparts but it never reformatted the date.

Re: format date

PostPosted: Mon Mar 05, 2012 1:16 pm
by MicoX
only one thing, a comma in the line must be removed
Code: Select all
var dateFormat=dateParts[1]+'-'+dateParts[2]+''-'+dateParts[0];

must be
Code: Select all
var dateFormat=dateParts[1]+'-'+dateParts[2]+'-'+dateParts[0];


:D

Re: format date

PostPosted: Mon Mar 05, 2012 2:07 pm
by chris
Well spotted, thanks :)

Chris

Re: format date month display

PostPosted: Mon May 19, 2014 6:03 pm
by Razoredger
I would like to display the month in text format in the date picker field but no matter how I modify the date_format it still outputs numbers only.
ie: 27/01/2014
Here is the code I understnd must be modified.
Code: Select all
    // format date
function get_cal_update_date($id_item){
   if(AC_DATE_DISPLAY_FORMAT=="us")   $date_format   = "%m-%d-%Y";
   else                         $date_format   = "%d-%m-%Y";


I have replaced "m" by mm, mmm, M, F....I have tried every PHP parameter I could find, but still no luck, display format is 27/01/2014. I have looked at $month, data-date.. no clue

So please where do I need to modify things and how to display 27 January 2014 instead of 27/01/2014 ?

Not sure if this formu is still alive, but throwing this SOS bottle out to sea...
Best Regards :)

Re: format date

PostPosted: Tue May 20, 2014 1:47 am
by Razoredger
This still doesn't work, but I succeeded in getting the month name instead of number. The only problem is when I click a date in July is displays January :o

Re: format date

PostPosted: Wed May 21, 2014 11:15 am
by chris
Hi,
Which date display are you referring to exactly?

Chris

Re: format date

PostPosted: Wed May 21, 2014 11:17 am
by chris
If you are referring to the date that is displayed when you hover over the dates in the calendar, try the following:

In ac-includes > functions.inc.php, replace these lines (ln 126 & ln 127):

Code: Select all
if(AC_DATE_DISPLAY_FORMAT=="us")   $date_format   =   $month."/".$day_counter."/".$year;
        else                           $date_format   =   $day_counter."/".$month."/".$year;


with:
Code: Select all
$date_format= strftime('%d %B %Y', strtotime("".$month."/".$day_counter."/".$year.""));


Chris

Re: format date

PostPosted: Wed May 21, 2014 9:52 pm
by Razoredger
Thank you, it worked! I modifed it to keep the same structure since my calender uses both US and French date formatting. I understood I needed to use strftime and strotime but was clueless as to where to put those puzzle pieces.
In answer to your questions. about which dates, they are the dates that are clicked in the calendar and displayed within a form for inputs dateStart and dateEnd. This is discussed elsewhere on the forum under the integration with a form topic.

To clarify with in functions.inc.php this is, here's a wider swath of code including what you just helped me with:

Code: Select all
//   format date for db modifying - the date is passed via ajax
      $date_db      =   $year."-".sprintf("%02s",$month)."-".sprintf("%02s",$day_counter);
        //   format date for display only
        if(AC_DATE_DISPLAY_FORMAT=="us")
            $date_format  = strftime('%B %d %Y', strtotime("".$month."/".$day_counter."/".$year.""));
// format for FR and ES
        else $date_format  =  strftime('%d %B %Y', strtotime("".$month."/".$day_counter."/".$year.""));


Thank you again. :D