WordPress.org

Ready to get started?Download WordPress

Forums

spell out the time (16 posts)

  1. icco
    Member
    Posted 9 years ago #

    I would like help. (duh). on my site i want to present the time in a format where the numbers are spelled out. like two o'clock and thirty minutes PM. can anyone tell me how to do this with the_date() or any other wordpress tag?

  2. RosieMBanks
    Member
    Posted 9 years ago #

    I'm not much of a WordPress maven, but since nobody answered your question yet I thought I'd give it a try.

    I found this thread, which mentions these PHP codes.

    That page lists examples like this:

    The time is <?php print date("H:i") ?>.
    That means it's <?php print date("i") ?>
    minutes past <?php print date("H") ?> o'clock.

    Which will give you an output like this:

    The time is 15:26. That means it's 26 minutes past 15 o'clock.

    I tried it on my site and it worked, but it gave me output just like the example: "15 o'clock," rather than "3 o'clock."

    The other URL mentioned in the thread says lower case "g" will give you a "12-hour format of an hour without leading zeros" and I tried this:

    The time is <?php print date("g:i") ?>.
    That means it's <?php print date("i") ?>
    minutes past <?php print date("g") ?> o'clock.

    And I got:

    The time is 3:26. That means it's 26 minutes past 3 o'clock.

    I hope this helps.

  3. Kafkaesqui

    Posted 9 years ago #

    Converting numbers to words can be done, but it's not easy. There are a few ways I know of to do this in PHP without writing everything from scratch. One involves the PEAR Numbers_Words package:

    http://pear.php.net/package/Numbers_Words

    There's also a third-party PHP class called Numbers2Words. You can search for it through Google:

    http://www.google.com/search?q=numbers2words+php+classes

  4. icco
    Member
    Posted 9 years ago #

    thanks guys ill try these out

  5. icco
    Member
    Posted 9 years ago #

    well im checking out te numbers2words.php, i've got to figure out how to properly use it, seeing as how php isn't my forte, but i shal prevail.

  6. icco
    Member
    Posted 9 years ago #

    ok this is turning out to be alot easier than i thought. First i had to drop the numbers2words.php into the plugins foloder along with runphp (im testing it in my posts). now ive just gotta figure out how to take the date and turn it into words :p

  7. icco
    Member
    Posted 9 years ago #

    this is what im trying:

    <?
    include('numberstowords.php');
    $bob=the_time('g');
    $NW= new numberstowords();
    echo $NW->n2w($bob)."\n";
    ?>

    but i'm getting 12 instead of twelve

  8. icco
    Member
    Posted 9 years ago #

    any ideas?

  9. vkaryl
    Member
    Posted 9 years ago #

    I couldn't find the absolutely antique script I had years back that did this sort of thing, sorry. You do realize that this is seriously annoying though, having to parse words instead of simply see the time?

  10. Joshua Sigar
    Member
    Posted 9 years ago #

    Can you paste the source code right here http://pastebin.com ?

  11. icco
    Member
    Posted 9 years ago #

    yes, it's ment to be rather annoying. :p

    here it is
    http://pastebin.com/299458

    let me add that normally to get it to work, you use

    <?
    include('numberstowords.php');
    $NW= new numberstowords();
    echo $NW->n2w(12)."\n";
    ?>

    but where that 12 is i want to put the time variable.

  12. Joshua Sigar
    Member
    Posted 9 years ago #

    your code works for me; have no clue why it doesn't work for you

  13. icco
    Member
    Posted 9 years ago #

    with the variable or just with numbers?

  14. Joshua Sigar
    Member
    Posted 9 years ago #

    both

  15. icco
    Member
    Posted 9 years ago #

    really? could you send me a link of it working? it really just isn't working for me. where are you putting it?

  16. icco
    Member
    Posted 9 years ago #

    bump

    anyone else get this to work?

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags