• 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?

Viewing 15 replies - 1 through 15 (of 15 total)
  • 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.

    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:

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

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

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

    Thread Starter icco

    (@icco)

    thanks guys ill try these out

    Thread Starter icco

    (@icco)

    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.

    Thread Starter icco

    (@icco)

    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

    Thread Starter icco

    (@icco)

    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

    Thread Starter icco

    (@icco)

    any ideas?

    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?

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

    Thread Starter icco

    (@icco)

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

    here it is
    https://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.

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

    Thread Starter icco

    (@icco)

    with the variable or just with numbers?

    both

    Thread Starter icco

    (@icco)

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

    Thread Starter icco

    (@icco)

    bump

    anyone else get this to work?

Viewing 15 replies - 1 through 15 (of 15 total)
  • The topic ‘spell out the time’ is closed to new replies.