Forums

Format date field

dion 08 Mar, 2009
I'm trying to show date where record inserted using recordtime field.
but when i user
echo date('d-m-Y',strtotime('{recordtime}'));
it alway return 01-01-1970 .
did i do something wrong?
GreyHead 08 Mar, 2009
Hi dion,

Where are you trying to do this? You can only use the { } syntax in the email template.

Bob
dion 09 Mar, 2009
i'm using it at ChonoConnectivity, at "body".

    <table style="text-align: left; width: 100%;" border="0" cellpadding="2" cellspacing="0">
      <tbody>
        <tr<?php if ($i % 2) echo ' style="background-color: #EBEBEB;"';?>>
          <td style="width: 10%;">
<?php 
echo date('d-m-Y',strtotime('{recordtime}'));?>
</td>
          <td style="width: 15%;">{region}</td>
          <td style="width: 15%;">{shift}</td>
          <td style="width: 5%;">{Lalin}</td>
          <td style="width: 15%;">{tunai}</td>
          <td style="width: 15%;">{PPC}</td>
        </tr>
      </tbody>
    </table>
    <?php $i++ ?>
Max_admin 09 Mar, 2009
it should be like this:

    echo date('d-m-Y',strtotime($row->recordtime));
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
dion 10 Mar, 2009
it works..!! 😀
THANK YOU
Bullfn33 20 Jun, 2011
I've tried the above code along with everything else under the sun and can't get the correct format to show up.

I'm trying to get a strftime format of "%B %e, %Y, %l:%M %p CT" to show up in the header box with no luck. My last futile effort was:

<?php
    $db =& JFactory::getDBO();
    $user =& JFactory::getUser();

    $query = sprintf('SELECT `recordtime` FROM %s WHERE `cf_user_id` = %d',
      $db->nameQuote('#__chronoforms_xxxx'),
      $user->id
    );
    $db->setQuery($query);
    $result = $db->loadResult();
    $t = strtotime("$result");

    echo "Last Saved on ", date("%B %e, %Y, %l:%M %p",strftime($t));
    ?>


any help appreciated
-John
GreyHead 21 Jun, 2011
Hi bullfn33,

This line will cause some problems
echo "Last Saved on ", date("%B %e, %Y, %l:%M %p",strftime($t));
[list=a]
  • The , will break the PHP; it needs to be a .

  • The PHP date() function doesn't use % in its format string.

  • The PHP strftime() function does use %; but the first parameter is a format string, not a timestamp.
  • [/list:o]
    Please try
    echo "Last Saved on ". strftime("%B %e, %Y, %l:%M %p", $t);

    Bob
    Bullfn33 21 Jun, 2011
    I tried the line above but it seems there is some conversion problem to the $t variable. I tried a bunch of different ways to get it to convert to a readable time but all I get is December 31, 1969 or August 21, 1970. The last thing I tried was this

    <?php
        $db =& JFactory::getDBO();
        $user =& JFactory::getUser();
    
        $query = sprintf('SELECT `recordtime` FROM %s WHERE `cf_user_id` = %d',
          $db->nameQuote('#__chronoforms_xxxx'),
          $user->id
        );
        $db->setQuery($query);
        $result = $db->loadResult();
    
        $result = date('YY-MM-DD - HH:MM:II');
        $t = strtotime($result);
    
        echo "Last Saved on ". strftime("%B %e, %Y, %l:%M %p", $t);
        
        ?>
    GreyHead 22 Jun, 2011
    Hi bullfn33,

    Please check the PHP manual for the correct settings to use with PHP functions: date('YY-MM-DD - HH:MM:II') returns 20112011-JunJun-WedWed - 1414:JunJun:11 which probably isn't what you intended.

    Also notice that strtotime() will interpret a date as being in US 'month day year' format if that makes sense so 11-06-22 will be interpreted as 6 Nov 2022

    Bob
    This topic is locked and no more replies can be posted.