Date and Time in UTC and local format in Magento - date

I display date and time in Magento page. Time displayed is from server (I guess) and I need my local time with (UTC +4:00) I used the below code (thanks for suport) :
<div class="header-right"><div class="clear"></div>
<div style="text-align: right;" class="date-time">
<?php echo strftime('%c');?>
</div>
Any support will be highly apreciated.
Site: www.ozams.com

You need to use only server time because of problems with local time. If your local time is wrong, so wrong date will be displayed.
I hope next links will help you in formatting:
Magento: Date format troubles
Playing with dates in magento
Guide through Magento’s timezones
I guess your problem is in your settings

To render local time in .phtml file, try
<?php // Render local date and time ?>
<?php echo $this->formatDate(null, Mage_Core_Model_Locale::FORMAT_TYPE_SHORT, true); ?>
<?php // Render local date ?>
<?php echo $this->formatDate(); ?>

Related

Wordpress - I need to add date AFTER the title

I have some code and I'm trying to add a line-break, than the date. In the current code it shows the date than the title on the same line.
Can someone help?
<div class="post-title">
<?php the_title('<div class="entry-title title-h4">', '</span></div>'); ?>
</div>
All help is appreciated! The date and text line is at the end of the code block.
Edit: I have managed to reverse the data successfully, but the date is no longer styled properly and doesn't follow the correct style. How do I move the date and keep it styled? Here's the code I ended up with:
<div class="post-title">
<?php the_title('<div class="entry-title title-h4">', '</span></div>'.(!$params['hide_date'] ? get_the_date('d M').': ' : '')); ?>
</div>
Edit 2:
I've gotten a little further. I successfully placed the date at the end of the text and kept it styled. But I'd like to have it under the title, I want to add a line-break. Anyone? Here's the code I ended up with:
<div class="post-title">
<?php the_title('<div class="entry-title title-h4">', '</span>'.(!$params['hide_date'] ? get_the_date('d M').' ' : '').'</div>'); ?>
</div>
I figured it all out by myself. Figured I'd post the answer here in-case someone needed this someday.
<div class="post-title">
<?php the_title('<div class="entry-title title-h4">', '</span>'.'<br>'.(!$params['hide_date'] ? get_the_date('d M').' ' : '').'</div>'); ?>
</div>

Getting HTML of a Cake PHP form

I am creating a form using Cake PHP. Is there any way to retrieve the basic HTML of the created form. For example,if we use Form Helper, we can create form using PHP itself. But now, I need only the html part of the created form for other use. Is it possible to retrieve it??
For example, say if I give input form like,
<?php
echo $this->Form->create('User');
echo $this->Form->input('email');
echo $this->Form->end('Save');
?>
I need output like this
<form action="index.html">
<input type="email" />
<input type="submit" value="Save" />
</form>
I can even create seperate function for attaining this objective. But I would like to know, if there is any other method for achieving this output
you can store FormHelper output in a string variable
<?php
$html_string = '';
$html_string .= $this->Form->create('User');
$html_string .= $this->Form->input('email');
$html_string .= $this->Form->end('Save');
?>
and then use your string elsewhere. But I'm not sure this is what you're searching for.
If I understand the question correctly, you want to use the form you created on another part of your site?
If that is the case, I would put the form itself in an Element and then call the Element wherever I wanted the form.
View/Elements/form.ctp
<?php
echo $this->Form->create('User');
echo $this->Form->input('email');
echo $this->Form->end('Save');
?>
Then in any view on your site you can call the Element using:
<?php echo $this->element('form');?>

Date format in a function WordPress ACF

I have asked a similar question in the past but still have issues...
I am therefore placing the whole function here.
Can anyone tell me how to change the format that the date is output?
Currently it shows 20130731
I want it to show 31st July 2013
function le_detail() {
?>
<div class="event">
<!--Standard WP - use 'echo' -->
<h2 class="button"> <?php echo get_the_title(); ?> </h2>
<!-- ACF - NO 'echo' -->
<h3><?php the_field('where'); ?></h3>
<h3><?php the_field('when'); ?></h3>
<p><?php the_field('description'); ?></p>
<p>Chairman: <?php the_field('chairman'); ?></p>
</div>
<?php
}
The date is the line: (this is using the Advanced Customs Fields plugin)
<h3><?php the_field('when'); ?></h3>
Yes, I had this same problem until I tried it this way:
$date = DateTime::createFromFormat('Ymd', get_field('my_datefield'));
//use your field name
then...
<li>Ticket Date: <?php echo $date->format('d M, Y'); ?> </li>
Good Luck!
ACF plugin is having get_field('') function to get the value of the custom field. Since you have used 'when' as the field name, so do as follows:
<h3><?php echo date("dS F,Y",strtotime(get_field('when'))); ?></h3>
Use the above code snippet, that will solve your problem.

Simplepie set_feed_url feed

and thanks in advance for your help. I'm using Simplepie to try to bring this feed:
http://www.p2rx.org/webservices/rssNews.cfm?Type=Tribal&getall=true
into this page:
http://www.tribalp2.org/events/news.php
As you can see, it isn't working. Although many other feed urls I've entered into:
$feed->set_feed_url('http://www.p2rx.org/webservices/rssNews.cfm');
work just fine. I've added
$feed->force_feed(true);
as well. What might the problem be? The full code is:
<?php
require_once('../php/autoloader.php');
$feed = new SimplePie();
$feed->set_feed_url('http://www.p2rx.org/webservices/rssNews.cfm?Type=Tribal&getall=true');
$feed->force_feed(true);
$feed->init();
$feed->handle_content_type();
?>
<?php foreach ($feed->get_items(0,30) as $item): ?>
<div class="item">
<h4><?php echo $item->get_title(); ?> - <?php echo $item->get_date('F j, Y'); ?></h4>
<p><?php echo $item->get_description(); ?></p>
</div>
<?php endforeach; ?>
<?php unset($feed); ?>
Thanks.
SimplePie can not display all feeds. There are crap feeds that do not follow the standards and even if you try to force it, SimplePie can not decipher them. However checking http://validator.w3.org/feed/ your feed validates.
Try not forcing feed, also try calling force feed after init. If the feed validates SimplePie should handle it.

Format date in the indexSuccess.php

I want to format the created_at field date from the original for something like 03.May.2011 to be shown in the indexSuccess.php and in the showSuccess.php
Could you help me?
thanks
You can make in symfony in your indexSuccess.php and showSuccess.php instead of for example:
<?php $value->getCreatedAt() ?>
next:
<?php echo date('d.M.Y', strtotime($value->getCreatedAt())) ?>
You can use other formats.
The format of some data absolutely not belongs into controller context - so please use
use_helper("date");
echo format_date($myDate);
from symfony's date helper in your template (showSuccess.php, blaSuccess.php) or partial (form.php, list.php, test.php) !
You'll find more informations here http://www.symfony-project.org/gentle-introduction/1_4/en/13-I18n-and-L10n#chapter_13_sub_outputting_data_in_the_user_s_culture or in the source file.
I believe the date is returned in a string format Y-m-d H:i:s, as fits the MySQL datetime type. It would be nicest to convert this to a PHP DateTime instance using DateTime::createFromFormat, presuming you are using PHP > 5.3.
So, in your controller:
$this->creation_date = DateTime::createFromFormat('Y-m-d H:i:s', $item->created_at);
Then, in your view:
<?php echo $creation_date->format('d.F.Y') ?>
See also DateTime::format
If you are using PHP 5.2 or before, you can't use createFromFormat. You probably want to fall back on strtotime:
$this->creation_date = strtotime($this->created_at);
and in the view:
<?php echo date('d.F.Y', $creation_date) ?>
To create a datestring like your example (03.May.2011) use this way:
<?php use_helper("date"); ?>
<?php echo format_date($myDate,'dd. MMM. yyyy'); ?>