ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Getting to 12:00 am from NOW

April 25, 2011 10:06am

Subscribe [3]
  • #1 / Apr 25, 2011 10:06am

    CDT

    93 posts

    Hi, All

    If this is elsewhere in the forum, I apologize, but I’d searched for this previously in the forums, but “now” yields far too many results.) My forum-foo doesn’t seem to be with me on this one.)

    <?php $work_days = ($total_projects * 2); ?>
    <?php $delivery_days = $work_days; ?>
    
    <?php 
        $start_day_month = 
            $this->EE->localize->decode_date('%F', 
                $this->EE->localize->now + (86400 * $work_days) + 86400); 
    ?>

    There is more code before this (including a channel tag) and all is working great, and there’s more after this. EXCEPT…

    What I would like to be able to do is adjust “NOW” so that I’m always starting at the same time before performing any calculations. As is, the calculation could be off by as much as 23+ hours and change. If someone looks at it @ 12:01 am or 11:59 pm, the resulting calculation will be a day off (not wanting that). We don’t care if it starts our calculation at 12:00 am or 12:00 pm or any other time (we’ll adjust the calculation accordingly), just for it to be fixed, but “today.”

    How would I do that, to change “now,” so it is “today” at 12:00 pm or 12:00 am? Would I use something besides “now”?

    Thanks in advance!

  • #2 / Apr 25, 2011 11:53am

    jjpmann

    4 posts

    Hi,

    I am working on a EE plugin at the moment that can add days, months and/or years to current date or a set date. Does this sound like something you could use to get the calculations required for your project?

  • #3 / Apr 25, 2011 12:02pm

    CDT

    93 posts

    Not sure. This is not a calculation we’re applying to a channel tag. I’m sorry. I should have included more of the template so that was clear. We’re just picking up the count of total_results and using that to multiply by.

  • #4 / Apr 25, 2011 6:30pm

    Hmm, maybe something with mktime would help?

  • #5 / Apr 26, 2011 11:52am

    CDT

    93 posts

    Thanks, Dylan. I get the shivers when looking at the php reference guide, but I suspect you’re correct. EE is just enough different in syntax that I go a bit cross eyed trying to make the conversion from there to here.

    “Now” is probably not the correct thing to be using, or I must have to incorporate mktime (or something like it) in there somehow. It’s the “how” that baffles me. I don’t really need time (hours and minutes) in the calculations. We’re only using days. We need X times the “count” (results) from today, plus Y number of days.

    If I’m interpreting it correctly, mktime appears to be for the purpose of calculating the delta between specific dates, such as the delta between January 1, 1998 and December 4, 2001. We’re not interested in specific dates. We’re interested in performing calculations, but in forecasting a date based on today, multiplied by certain factors.

    :(

    Thanks though. Something else must do something similar. I thought there must be a way of stripping “Now” down to just a day, rather than minutes, but I have no idea how to do that either (or it that’s the correct approach).

    DateTime://:modify might be what I need.  I’ll report back if it works. Or if anyone else has any ideas, let me know?

  • #6 / Apr 26, 2011 12:11pm

    CDT

    93 posts

    Changed some of channel tag to maintain the confidentiality of it all, but the gist of it is still intact (I hope). Here’s the full calculation (with the values changed) so you get more of the idea of what we’re trying to do, and a picture of the results. Really simple calculations. We just want, as I said originally, that we could fix the starting point of the calculation to be 12:01 am instead of whatever time “now” is!

    {exp:channel:entries channel="channel_name" show_future_entries="yes" rdf="off" status="open" dynamic="off" disable="categories|pagination|category_fields"}
    
    {if no_results}
        <?php $total_projects = "1" ; ?>
    {/if}
    
    {if "{count}" == "1"}
        {if total_results == "1"}
            <?php $total_projects = "1" ; ?>
        {if:else}
            <?php $total_projects = "{total_results}" ; ?>
        {/if}
    {/if}
    
    {/exp:channel:entries} 
    
    <?php $work_days = ($total_projects * 3); ?>
    
    <?php 
        $start_day_month = 
            $this->EE->localize->decode_date('%F', 
                $this->EE->localize->now + (86400 * $work_days) + 86400); 
    ?>
    
    <?php 
        $start_day_date = 
            $this->EE->localize->decode_date('%j', 
                $this->EE->localize->now + (86400 * $work_days) + 86400); 
    ?>
    
    <?php 
        $start_day_day = 
            $this->EE->localize->decode_date('%l', 
                $this->EE->localize->now + (86400 * $work_days) + 86400); 
    ?>
    
    
    <div id="turnclock">
    
        <table class="turnclock">
        <tr>
            <td class="tc_day">
                <?php echo $start_day_day; ?>
            </td>
        </tr>
        <tr>
            <td class="tc_date">
                <?php echo $start_day_month; ?>
                <?php echo $start_day_date; ?>
            </td>
        </tr> 
        </table>
    </div>

    See it live.

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases