Support

Home Forums Event Espresso Premium Gte the event Dat Function – EEH_Event_View::the_event_date – Not working?

Gte the event Dat Function – EEH_Event_View::the_event_date – Not working?

Posted: December 1, 2014 at 5:58 am


Zoe E

December 1, 2014 at 5:58 am

Hello,

I am creating a custom widget for a website we are building due to we need a very custom widget all is working well however having issues with getting the time / date to display properly.

So to start of with un-aware with the built in function. I did the following code:

global $wpdb;
                $rowdatetime = $wpdb->get_row("SELECT * FROM wp_esp_datetime WHERE EVT_ID = $EVT_ID");

$startdatetime = strtotime($rowdatetime->DTT_EVT_start);
                $starttime = date("jS F @ g:ia", $startdatetime);
                $enddatetime = strtotime($rowdatetime->DTT_EVT_end);
                $endtime = date("g:ia", $enddatetime);
                $currentdatetime = date("jS F @ g:ia");

This worked however the times displaying on the website were an hour early. So i look into the code of event expresso and found
espresso_event_date();
So did the Following piece of code.



espresso_event_date('jS F',  'g:ia',  $EVT_ID);
espresso_event_end_date( 'jS F',  'g:ia',  $EVT_ID);

now first of these are echoing there output, which a function should not really be doing, (I need to pass them into another variable)
second and more importantly they are giving me todays date and time not the event date and time. I believe it is to do with when i change the format i want the date and time to be in that causes it to fail.

Is there a custom way that I can change the date format to display the correct time, and not an hour earlier?

Many Thanks


Lorenzo Orlando Caum

  • Support Staff

December 1, 2014 at 11:44 am

Hi,

The date times for events are stored in the database as UTC and then are adjusted based on your WordPress timezone settings.

Do you have WordPress set to use a city or region near you through WP General Settings?


Lorenzo


Zoe E

December 3, 2014 at 1:58 am

Yes we do we have it set to london.

Basically i want to output:
5th August @ 9:00am – 5:00pm

Something like that with the date the start time and end time.

I have got it to out put the date and time by using the functinos and creating my own with the following code.


//now get the date and titme for the event
                global $wpdb;
                $rowdatetime = $wpdb->get_row("SELECT * FROM wp_esp_datetime WHERE EVT_ID = $EVT_ID");

                //get the Start Date
                $startdate = date_i18n( "jS F", convert_datetime($rowdatetime->DTT_EVT_start), false );

                //Function to get the time the event starts
                if ( ! function_exists( 'espresso_event_custom_date' )) {
		            function espresso_event_custom_date($tm_frmt = 'g:i a', $EVT_ID = FALSE ) {
                        $dt_frmt = '';
			            return date_i18n( $tm_frmt, strtotime( EEH_Event_View::the_event_date( $dt_frmt, $tm_frmt, $EVT_ID )));
		            }		
	            }

                //Get the event end time
                if ( ! function_exists( 'espresso_event_custom_end_date' )) {
		            function espresso_event_custom_end_date($tm_frmt = 'g:i a', $EVT_ID = FALSE ) {
                        $dt_frmt = '';
			            return date_i18n( $tm_frmt, strtotime( EEH_Event_View::the_event_end_date( $dt_frmt, $tm_frmt, $EVT_ID )));
		            }		
	            }

                $starttime =  espresso_event_custom_date('g:ia',  $EVT_ID);
                $endtime =  espresso_event_custom_end_date('g:ia',  $EVT_ID);
                $output .= '<div class="eventtime">'.$startdate.' @ '.$starttime.' - '.$endtime.'</div>';

However I feel that code is somewhat hacky to get what I want. Is there a better more efficiently ways to do it?

Many Thanks.


Lorenzo Orlando Caum

  • Support Staff

December 3, 2014 at 6:15 am

Hi,

You could create a customized version of the espresso_list_of_event_dates function. There is an example here (towards the bottom of page):

https://gist.github.com/lorenzocaum/ac217033f12232404cce#comment-1348273

The new function as is will look like this:

http://cl.ly/image/3j2I252G2R1P

However, you could customize it further.


Lorenzo

The support post ‘Gte the event Dat Function – EEH_Event_View::the_event_date – Not working?’ is closed to new replies.

Have a question about this support post? Create a new support post in our support forums and include a link to this existing support post so we can help you.

Event Espresso