Wordpress display the posted date - wordpress

I display a list of my recently posted custom posts. However i would like to display when it was posted with the get_the_date() function.
I would like the date to be displayed like this.
If it is posted today: just the time it was posted (18:24)
If it was posted this year: The day + month (22 may)
If it was posted before the current year: The normal date (2016-10-11)
Is this possible to do?
Thanks in advance! /Molle

Yes, this is possible to do, provided you can write PHP yourself within your WordPress page or create your own template to take advantage of said PHP.
If you have the date of the post loaded in a variable already (assuming you do), then you can use your own logic (if, else is statements as literally stated by your question) to parse out the day and year.
Read more on date formatting to get the desired output you wish:
http://php.net/manual/en/datetime.formats.date.php

Related

Wordpress Post Date, shows month by number and text

I am having troubles with my Worpress post date. As the picture shows, I can publish the post with 01-Jan etc. I only want to post the month with text, and no numbers. Any suggestions?
You mentioned in the comments that the date on the front end was displayed wrong. Therefore, I suggest you look at the PHP source that is creating that page.
It's possible that the date format has been explicitly set in there, especially if you are using a non-custom theme, so the format under 'Settings -> General' could be ignored.

Wordpress reverse date format for display but not db

I have a events page using a custom wp_query so that I can split post into upcoming events and past events. To do this I need the date to be stored in the database Y/m/d format but would like it to display on the front ends d/m/y. Any help on how I should do this, I could reverse it with jquery but there might be a better way?
thanks
That page is probably using the_date() function.
If so, modify it using format parameter to something like this:
the_date('d/m/Y');
Check also this Codex page about formatting the date and time.

create date formatted custom_meta field in wordpress admin

I have created a custom meta field to be used within a custom post type, that is to be the start time of a series of events. However, I would like to run my query_posts off of this value, but it is not formatted in date/time format, therefore '1:00pm' shows up in the list before '9:00am'. Is it possible to format this value in the db or at least prior to setting the 'meta_key' meta_value in my arguments for my query?
I've come across this problem a few times before. I'm going to use my most recent example because it sounds like it's along the same lines of what you're doing.
I had to create an event calendar using WordPress. In my custom post type, I had two fields: a start time and an end time. Instead of just using "1:00pm" as the start and end times, I also included the dates. This would allow for events that would last an entire weekend like a concert or a race.
What I'm getting at here, is once the user submitted that the event started on January 3, 2012 at 8:00 am and ended on January 3, 2012 at 10:00 am, I saved both of the variables using strtotime(). If you're not familiar with this function, you can read more about it here: http://us.php.net/manual/en/function.strtotime.php.
I also suggest using the datetime picker add-on for jQuery UI http://trentrichardson.com/examples/timepicker/.
I hope this helped. I know I was a little vague at times. If you need me to explain anything in more detail, don't be afraid to ask.

Reporting Services: DateTime parameter not showing the time part when its midnight

I need to add a 'StartDate' parameter to a report in Reporting Services 2005, which should represent the current date, at midnight.
If I use Now() as expression, it will correctly use midnight in the calculations, but to the user, the time part will not be shown.
13/12/2011
which can be confusing because then the user doesn't really realise he or she can type in a time part.
How can I format this date to the following:
13/12/2011 00:00
while keeping the parameter as a DateTime datatype.?
Edit: I've checked the duplicate question and tried to apply it to my case, but run into the following phenomenom:
If I try:
=DateTime.Parse(Format(Now().Date().AddSeconds(1), "dd/MM/yyyy HH:mm:ss"))
Then the parameter shows "14/12/2011 00:00:01" which is confusing for the users, so I then tried the following:
=DateTime.Parse(Format(Now().Date().AddSeconds(1), "d/M/yyyy HH:mm"))
But then the parameter shows "14/12/2011" again! In other words, the time part is gone again!
Who invented this stuff? :P
Your formula with .Parse(Format(... causes redundant work that is messing things up. Try this:
=Now().Date().AddSeconds(.001)
Use Format. For example: Format(Parameters!SelectedDate.Value, "d/M/yyyy HH:mm")
Here is a list of DateTime identifiers for use with Format.
Edit:
I get it now, you want 00:00 to show up in the parameter input calendar in the report viewer. The time part won't show up when it's set to midnight. This is by design. If you're using 2005 or earlier, Jamie's solution won't work and you're stuck.

In Wordpress: Group same-day posts on the index page

i'm looking for a way to code the loop in such a way that it places posts that are in the same day within a div. Im doing this so I can put a separator between the different days to show users that they are looking at another day. An example of this in action is in informedlondon.com, where once a days worth of posts ends, there is a little graphic in between to separate the posts. This is what Google's Blogger platform does by default, thats why it was easy for the divider to be put between the different days of posts.
I'm guessing there must be a tutorial about it somewhere but I have checked and can't seem to find one. I have a sneaky suspicion that it's very easy and i'm just being a dunce. Would appreciate some help.
Many thanks in advance.
The simplest method to accomplish things like this is to 'hold' the current date in a variable. Before your loop: var $current_date and then inside your loop, a simple if statement:
if( $current_date != get_the_date('d-m-Y') ){
echo '<h2>Posts for '.get_the_date('d-m-Y').'</h2>';
$current_date = get_the_date('d-m-Y');
}
So in effect, you're checking with each post whether the date of the post is different than the date of the last post rendered (in the 'holding' variable, $current_date). If it is, you print a title with the new date, and set the 'holding' variable to the new date. If not, nothing happens and the post is printed as usual.

Resources