Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have som problems with the date functions in wordpress.

I am trying to get different format on the post date on some pages and i have been trying "the_date()","the_time()" and "echo get_the_date()". They all behave in the same way.

They output the correct date format when i just type for example the_time(). The output is the format i had setup in wordpress settings, as expected.

The problems is that when i try to format the output by ex: the_time('d') the output is "d" or echo get_the_time('F j, Y'); the output is "'F j, Y'".

I forgot to mention that the code is inside "the loop"

This is my page.php

<?php get_header();?>
<?php get_sidebar('subnav');?>
<section class="main-content2" id="page">
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<h1><?php the_title();?></h1>
<?php the_content();?>
<footer class="meta">Publicerades den <?php echo get_the_date('d');?></footer>

<?php endwhile; else: ?>
<p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
<?php endif; ?>
</section>
<?php get_footer();?>    

I cannot understand what the problem is, please help!:)

share|improve this question
    
It should work, I guess. I don't see anything wrong with your code. Disable all plugins and check if this error still exists. Maybe some plugin is breaking things up. –  Krzysiek Dróżdż Jul 27 '13 at 12:15
add comment

1 Answer 1

When using date function it is recommanded to use date format or time format of the installation :

get_option('time_format');
get_option('date_format');

This allows you to grab date format or time format of the current installation.

share|improve this answer
1  
I guess Hiren knows that, but he want's to get different date format on some of pages. You can't do it with date format option. –  Krzysiek Dróżdż Jul 27 '13 at 12:13
    
ok, I see. In this case this should work. –  JMau Jul 27 '13 at 12:17
    
I have no problem getting the standard format. The problem occurs when trying to get a different date format. –  Hiren Kerai Jul 27 '13 at 12:18
    
The problem is now solved. The problem was with qtranslate, which was setup to use strftime instead of date. –  Hiren Kerai Jul 27 '13 at 12:34
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.