bwadamcik Posted September 28, 2015 Share Posted September 28, 2015 (edited) Here is the code how would I go about getting only the D/M or D/M/Y <?php $event_start_date = get_post_meta(get_the_ID(), 'event_start_date', true); $event_start_time = get_post_meta(get_the_ID(), 'event_start_time', true); $event_location = get_post_meta(get_the_ID(), 'event_location', true); if(!empty($event_start_date)) { ?> <?php global $redux_demo; if(isset($redux_demo['events-date-format'])) { $time_format = $redux_demo['events-date-format']; if($time_format == 1) { ?> <?php $start_unix_time = strtotime($event_start_date); $start_date = date("m/d/Y",$start_unix_time); ?> <?php } elseif($time_format == 2) { ?> <?php $start_unix_time = strtotime($event_start_date); $start_date = date("d/m/Y",$start_unix_time); ?> <?php } } else { ?> <?php $start_unix_time = strtotime($event_start_date); $start_date = date("m/d/Y",$start_unix_time); ?> <?php } ?> <?php global $redux_demo; if(isset($redux_demo['events-time-format'])) { $time_format = $redux_demo['events-time-format']; if($time_format == 1) { ?> <?php $start_time = esc_attr($event_start_time); ?> <?php } elseif($time_format == 2) { ?> <?php $start_time = date("H:i", strtotime($event_start_time)); ?> <?php } } else { ?> <?php $start_time = esc_attr($event_start_time); ?> <?php } ?> <span><?php echo esc_attr($start_date); ?> <?php echo esc_attr($start_time); ?></span> <?php } ?> Edited September 28, 2015 by cyberRobot added code tags Quote Link to comment https://forums.phpfreaks.com/topic/298334-php-returning-dmy-and-time-and-i-only-want-the-dm-or-dmy/ Share on other sites More sharing options...
QuickOldCar Posted September 28, 2015 Share Posted September 28, 2015 Nobody answered most likely because how much a mess the code was and a little bit more explanation needed as well. Get date from where exactly? I see some there now. <?php $event_start_date = get_post_meta(get_the_ID(), 'event_start_date', true); $event_start_time = get_post_meta(get_the_ID(), 'event_start_time', true); $event_location = get_post_meta(get_the_ID(), 'event_location', true); if (!empty($event_start_date)) { global $redux_demo; if (isset($redux_demo['events-date-format'])) { $time_format = $redux_demo['events-date-format']; if ($time_format == 1) { $start_unix_time = strtotime($event_start_date); $start_date = date("m/d/Y", $start_unix_time); } elseif ($time_format == 2) { $start_unix_time = strtotime($event_start_date); $start_date = date("d/m/Y", $start_unix_time); } } else { $start_unix_time = strtotime($event_start_date); $start_date = date("m/d/Y", $start_unix_time); } global $redux_demo; if (isset($redux_demo['events-time-format'])) { $time_format = $redux_demo['events-time-format']; if ($time_format == 1) { $start_time = esc_attr($event_start_time); } elseif ($time_format == 2) { $start_time = date("H:i", strtotime($event_start_time)); } } else { $start_time = esc_attr($event_start_time); } echo "<span>" . esc_attr($start_date) . esc_attr($start_time) . "</span>"; } ?> I especially do not understand why this multiple if/elesif/else statement 1,2 and default are all exactly the same. if ($time_format == 1) { $start_unix_time = strtotime($event_start_date); $start_date = date("m/d/Y", $start_unix_time); } elseif ($time_format == 2) { $start_unix_time = strtotime($event_start_date); $start_date = date("d/m/Y", $start_unix_time); } } else { $start_unix_time = strtotime($event_start_date); $start_date = date("m/d/Y", $start_unix_time); } Quote Link to comment https://forums.phpfreaks.com/topic/298334-php-returning-dmy-and-time-and-i-only-want-the-dm-or-dmy/#findComment-1521670 Share on other sites More sharing options...
QuickOldCar Posted September 28, 2015 Share Posted September 28, 2015 I think I know what you need after reading the title and also post a few times. echo "<span>" . esc_attr($start_date) . "</span>"; Quote Link to comment https://forums.phpfreaks.com/topic/298334-php-returning-dmy-and-time-and-i-only-want-the-dm-or-dmy/#findComment-1521671 Share on other sites More sharing options...
bwadamcik Posted September 28, 2015 Author Share Posted September 28, 2015 (edited) Hi QuickOldCar, I have no idea myself and I apologize for my sad excuse for a question. I did see the redundancy. I have a website that has the code prewritten and after inspecting it I was looking to modify a section to be more user friendly instead of listing the items by number providing the specific date event instead. I am hoping to figure out how to just remove the time portion in this code so that I can just present the date. How would it be best for me to present this question so it can be better understood? Bang Edited September 28, 2015 by bwadamcik Quote Link to comment https://forums.phpfreaks.com/topic/298334-php-returning-dmy-and-time-and-i-only-want-the-dm-or-dmy/#findComment-1521735 Share on other sites More sharing options...
QuickOldCar Posted September 28, 2015 Share Posted September 28, 2015 My next post I answered that, don't echo out the time portion. Here is an example using your code you posted. <?php } ?> <span><?php echo esc_attr($start_date); ?></span> <?php } ?> Quote Link to comment https://forums.phpfreaks.com/topic/298334-php-returning-dmy-and-time-and-i-only-want-the-dm-or-dmy/#findComment-1521742 Share on other sites More sharing options...
bwadamcik Posted September 28, 2015 Author Share Posted September 28, 2015 Hi QuickOldCar, I appreciate you giving me that information. I gave it a try and it didn't work. <?php if($currentEvent <= 9) { ?>0<?php } ?><?php echo $currentEvent; ?> this is what is currently there which reflects just a number. is there another method of writing it that you would suggest? Quote Link to comment https://forums.phpfreaks.com/topic/298334-php-returning-dmy-and-time-and-i-only-want-the-dm-or-dmy/#findComment-1521787 Share on other sites More sharing options...
scootstah Posted September 29, 2015 Share Posted September 29, 2015 (edited) Why are you going in and out of PHP tags on every line? That's completely unnecessary and makes your code very hard to follow. I am hoping to figure out how to just remove the time portion in this code so that I can just present the date. You can do that with date(). If you just have a date/time string instead of a UNIX timestamp, you can use strtotime() or the DateTime library to create one first. Edited September 29, 2015 by scootstah Quote Link to comment https://forums.phpfreaks.com/topic/298334-php-returning-dmy-and-time-and-i-only-want-the-dm-or-dmy/#findComment-1521911 Share on other sites More sharing options...
QuickOldCar Posted September 30, 2015 Share Posted September 30, 2015 <?php if($currentEvent <= 9) { ?>0<?php } ?><?php echo $currentEvent; ?> this is what is currently there which reflects just a number. is there another method of writing it that you would suggest? I don't see $currentEvent in your previous posted code. I appreciate you giving me that information. I gave it a try and it didn't work. I'm wondering how this didn't work. <?php } ?> <span><?php echo esc_attr($start_date); ?></span> <?php } ?> Does your original code work with date and also time? <?php } ?> <span><?php echo esc_attr($start_date); ?> <?php echo esc_attr($start_time); ?></span> <?php } ?> Quote Link to comment https://forums.phpfreaks.com/topic/298334-php-returning-dmy-and-time-and-i-only-want-the-dm-or-dmy/#findComment-1521955 Share on other sites More sharing options...
bwadamcik Posted September 30, 2015 Author Share Posted September 30, 2015 That is my very confusion when I try and use this code above which I thought would work it does not reflect and throws an error for this line. The only way the error doesn't occur is when I put the whole code snippet I provided in and then it reflects the whole m/d/y time. I figured that I would need to look at this to fix it and add an additional format? Any thoughts? global $redux_demo;if (isset($redux_demo['events-time-format'])) {$time_format = $redux_demo['events-time-format'];if ($time_format == 1) { Quote Link to comment https://forums.phpfreaks.com/topic/298334-php-returning-dmy-and-time-and-i-only-want-the-dm-or-dmy/#findComment-1521960 Share on other sites More sharing options...
scootstah Posted October 2, 2015 Share Posted October 2, 2015 And what would that error be? Quote Link to comment https://forums.phpfreaks.com/topic/298334-php-returning-dmy-and-time-and-i-only-want-the-dm-or-dmy/#findComment-1522138 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.