Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New Coder
    Join Date
    Mar 2007
    Posts
    98
    Thanks
    24
    Thanked 4 Times in 4 Posts

    Help to retrieve selected date using Epoch calendar

    Hi all,

    I'm using the Epoch calendar at:

    http://www.javascriptkit.com/script/...ch/index.shtml

    It works great and does exactly what I need. I'm using it in flat mode so that it can be displayed statically on the page. What I can't seem to work out is how to retrieve the selected date once clicked on. I need to be able to print the output in dd/mm/yyyy format, either on screen or in an alert or something similar.

    If anyone has worked with this calendar and knows how to do it, or can sort it, I'd appreciate it greatly. I can't paste code here as it's too long, but the source code on the site linked above is exactly the same as I'm using.

    Cheers!
    Last edited by longman; 06-18-2010 at 01:56 AM.

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,174
    Thanks
    75
    Thanked 4,339 Times in 4,305 Posts
    It looks to me like you can get the clicked on date by looking at the selectedDates property of the calendar you create.

    That is, if you do
    Code:
        var mycalendar = new Epoch(....);
    then you can use
    Code:
        var dates = mycalendar.selectedDates;
    Note that this will always be an array, even if there is only one date allowed/chosen (that's because the general calendar will handle multiple dates).

    So if you didn't ask for multiple dates, you could do
    Code:
        var pickedDate = mycalendar.selectedDates[0];
    Or, better:
    Code:
        var pickedDate = mycalendar.selectedDates.length > 0 ? mycalendar.selectedDates[0] : null;
    So that the value is null if no date has yet been chosen.

    ** I HAVE NOT TESTED THIS. ** I just got that by reading the code.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • Users who have thanked Old Pedant for this post:

    longman (06-18-2010)

  • #3
    New Coder
    Join Date
    Mar 2007
    Posts
    98
    Thanks
    24
    Thanked 4 Times in 4 Posts
    OP, you da man!! (as usual).

    Your suggestion worked great. The only thing I have to figure out now is to format the date into the dd/mm/yyyy format I need. At the moment it prints in the format: Thu Jun 17 00:00:00 UTC+1000 2010

    I appreciate the quick response mate.

  • #4
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,174
    Thanks
    75
    Thanked 4,339 Times in 4,305 Posts
    That means that it is *probably* an instance of a JavaScript Date object.

    So you can use the conventional ways of formatting it:
    Code:
    var dt = mycalendar.selectedDates.length > 0 ? mycalendar.selectedDates[0] : null;
    if ( dt != null )
    {
        var prettyDate = dt.getDate() + "/" + ( dt.getMonth() + 1) + "/" + dt.getFullYear();
    }
    ...
    If you insist on two digits for day an month it's only a bit more code:
    Code:
    if ( dt != null )
    {
        var dy = dt.getDate(); if ( dy < 10 ) dy = "0" + dy;
        var mn = dt.getMonth() + 1; if ( mn < 10 ) mn = "0" + mn;
        var prettyDate = dy + "/" + mn + "/" + dt.getFullYear();
    }
    or similar code.
    Last edited by Old Pedant; 06-18-2010 at 06:47 PM.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • Users who have thanked Old Pedant for this post:

    longman (06-18-2010)

  • #5
    New Coder
    Join Date
    Mar 2007
    Posts
    98
    Thanks
    24
    Thanked 4 Times in 4 Posts
    Perfect once again!! Thanks. Oh, and also thanks for including the "on purpose" typo in the code above, to keep me on my toes!!

    You're a legend.

  • #6
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,174
    Thanks
    75
    Thanked 4,339 Times in 4,305 Posts
    LOL! It wasn't on purpose! It's just what comes from touch typing. - and = are sise by sise [yeah, that's on purpose].
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •