doubledee Posted February 26, 2012 Share Posted February 26, 2012 What Date Format is this... echo '<div class="date">Published: ' . date('F j, Y', strtotime($publishedOn)) . '</div>'; And where can I find a listing of the different Date and Time Formats that will work with this? (I would like to display my date as "2012-02-26 2:40pm" for what it is worth...) Thanks, Debbie Quote Link to comment https://forums.phpfreaks.com/topic/257834-what-date-format-is-this/ Share on other sites More sharing options...
Pikachu2000 Posted February 26, 2012 Share Posted February 26, 2012 It's all in the manual: date Quote Link to comment https://forums.phpfreaks.com/topic/257834-what-date-format-is-this/#findComment-1321484 Share on other sites More sharing options...
doubledee Posted February 26, 2012 Author Share Posted February 26, 2012 It's all in the manual: date Okay, because I didn't see it here under date: http://www.php.net/manual/en/datetime.formats.date.php Debbie Quote Link to comment https://forums.phpfreaks.com/topic/257834-what-date-format-is-this/#findComment-1321486 Share on other sites More sharing options...
Pikachu2000 Posted February 26, 2012 Share Posted February 26, 2012 If it isn't there, you simply need to create the formatting string yourself using the formatting parameters in the manual page for date(). Quote Link to comment https://forums.phpfreaks.com/topic/257834-what-date-format-is-this/#findComment-1321492 Share on other sites More sharing options...
doubledee Posted February 26, 2012 Author Share Posted February 26, 2012 If it isn't there, you simply need to create the formatting string yourself using the formatting parameters in the manual page for date(). No, my point was the link you provided had the codes I was looking for, but the page I posted didn't... Thanks, Debbie Quote Link to comment https://forums.phpfreaks.com/topic/257834-what-date-format-is-this/#findComment-1321495 Share on other sites More sharing options...
Pikachu2000 Posted February 26, 2012 Share Posted February 26, 2012 OK. As long as you found what you needed. If it gives you trouble, post the problem. Quote Link to comment https://forums.phpfreaks.com/topic/257834-what-date-format-is-this/#findComment-1321499 Share on other sites More sharing options...
doubledee Posted February 26, 2012 Author Share Posted February 26, 2012 OK. As long as you found what you needed. If it gives you trouble, post the problem. This is what I came up with... echo '<p class="commentDate">Posted on: ' . date('Y\-m\-d g\:ia', strtotime($createdOn)) . '</p>'; Is that how you add Text to the Date/Time? Debbie Quote Link to comment https://forums.phpfreaks.com/topic/257834-what-date-format-is-this/#findComment-1321501 Share on other sites More sharing options...
litebearer Posted February 26, 2012 Share Posted February 26, 2012 remove the back slashes Quote Link to comment https://forums.phpfreaks.com/topic/257834-what-date-format-is-this/#findComment-1321505 Share on other sites More sharing options...
Pikachu2000 Posted February 26, 2012 Share Posted February 26, 2012 Such as what? Quote Link to comment https://forums.phpfreaks.com/topic/257834-what-date-format-is-this/#findComment-1321506 Share on other sites More sharing options...
doubledee Posted February 26, 2012 Author Share Posted February 26, 2012 remove the back slashes Do I only need backslashes when the character I want to use is also a special character (e.g. Y) ? Debbie Quote Link to comment https://forums.phpfreaks.com/topic/257834-what-date-format-is-this/#findComment-1321512 Share on other sites More sharing options...
doubledee Posted February 26, 2012 Author Share Posted February 26, 2012 Such as what? Such as what what?! Debbie Quote Link to comment https://forums.phpfreaks.com/topic/257834-what-date-format-is-this/#findComment-1321513 Share on other sites More sharing options...
Pikachu2000 Posted February 26, 2012 Share Posted February 26, 2012 Such as what? Such as what what?! Debbie I wasn't sure what text you were referring to when you ask how to add text to a date format. Quote Link to comment https://forums.phpfreaks.com/topic/257834-what-date-format-is-this/#findComment-1321516 Share on other sites More sharing options...
doubledee Posted February 26, 2012 Author Share Posted February 26, 2012 Such as what? Such as what what?! Debbie I wasn't sure what text you were referring to when you ask how to add text to a date format. Oh. I meant if you needed to things like... Published on: 2012-02-21 3:19pm Your Test is on 3/15/2012 at 10:00am in Room 101. It is now 11:30pm on 3/20/2012 Debbie Quote Link to comment https://forums.phpfreaks.com/topic/257834-what-date-format-is-this/#findComment-1321518 Share on other sites More sharing options...
litebearer Posted February 26, 2012 Share Posted February 26, 2012 would you backslash/escape this? (rhetorical) ... $message = "You haven't tested this, have you?"; echo $message; Quote Link to comment https://forums.phpfreaks.com/topic/257834-what-date-format-is-this/#findComment-1321524 Share on other sites More sharing options...
Anon-e-mouse Posted February 26, 2012 Share Posted February 26, 2012 Hello Debbie, Maybe I can help. You can look at formatting it the way you have with date() or you can use DateTime as below: <?php // Nice date.. $dt = new DateTime($dateyouareworkingwith); // Format! $dt->format("jS F Y") // Go. echo $dt; ?> For example using "jS F Y" as the format with the following timestamp: "2012-02-03 21:31:15" will format to "3rd February 2012". So with that all you need to put into DateTime is the timestamp you're working with and then format it in anyway you want without anything special. Equally with using date() you don't need to add blackslashes all over the place so.. <?php // Current datetime in Year-Month-Day Hour:Minutes:Second format.. echo date("Y-m-d H:i:s"); ?> That will echo out something like "2012-02-26 23:39:21" for me at the moment. The only reason the "-"'s are in there is to break up what would be just numbers and make it look semi-friendly. Hope it helps! Quote Link to comment https://forums.phpfreaks.com/topic/257834-what-date-format-is-this/#findComment-1321537 Share on other sites More sharing options...
doubledee Posted February 27, 2012 Author Share Posted February 27, 2012 would you backslash/escape this? (rhetorical) ... $message = "You haven't tested this, have you?"; echo $message; I went off what the Manual said... Debbie Quote Link to comment https://forums.phpfreaks.com/topic/257834-what-date-format-is-this/#findComment-1321539 Share on other sites More sharing options...
kicken Posted February 27, 2012 Share Posted February 27, 2012 Do I only need backslashes when the character I want to use is also a special character (e.g. Y) ? Yes, you only need to escape a character that is also a format code. Generally you should keep your date format string as free of extra characters as possible. So if you want to output something like this: Welcome, the current date and time is: 2/26/2012 7:17 Rather than include that whole string in the date call, you just do the date part and concatenate that to the rest: $now = date('m/d/Y g:i'); echo 'Welcome, the current date and time is: <b>'.$now.'</b>'; Quote Link to comment https://forums.phpfreaks.com/topic/257834-what-date-format-is-this/#findComment-1321542 Share on other sites More sharing options...
doubledee Posted February 27, 2012 Author Share Posted February 27, 2012 Do I only need backslashes when the character I want to use is also a special character (e.g. Y) ? Yes, you only need to escape a character that is also a format code. Generally you should keep your date format string as free of extra characters as possible. So if you want to output something like this: Welcome, the current date and time is: 2/26/2012 7:17 Rather than include that whole string in the date call, you just do the date part and concatenate that to the rest: $now = date('m/d/Y g:i'); echo 'Welcome, the current date and time is: <b>'.$now.'</b>'; Now there is some sage advice!! Thanks, Kicken! Debbie Quote Link to comment https://forums.phpfreaks.com/topic/257834-what-date-format-is-this/#findComment-1321543 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.