Solved

Variable into datetime Format

Posted on 2013-06-01
6
164 Views
Last Modified: 2013-06-02
How do I write this in PHP:

$date = "date_format(date_time'%a %c/%e')";

Open in new window

0
Comment
Question by:rgranlund
  • 2
  • 2
  • 2
6 Comments
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 39213424
There is something missing in your question like where are you getting this?  PHP has a 'date_format' function but not a "date_time'%a %c/%e'" function.

Also, I recommend that you do not use PHP reserved words like 'date' as variable names.  Can cause problems.
0
 
LVL 7

Author Comment

by:rgranlund
ID: 39213527
How do you "date_format" a variable that is a date?
0
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 39213539
The PHP date() function can format for just about any valid date.  However, what you posted above is not coming from PHP.  Where are you getting it?  What format is it in?  This is clearly not just a PHP question because PHP doesn't have all those functions.  And 'date' formats are not universal, many programs format them differently.
0
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
LVL 109

Accepted Solution

by:
Ray Paseur earned 230 total points
ID: 39214594
Required reading here:
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_201-Handling-date-and-time-in-PHP-and-MySQL.html
How do you "date_format" a variable that is a date?
If I am understanding it correctly it sounds like you have a date, perhaps in ISO-8601 format like 2013-06-02 and you would like to see it in a "pretty" format like June 2, 2013.
http://www.laprbass.com/RAY_temp_rgranlund.php

<?php // RAY_temp_rgranlund.php
error_reporting(E_ALL);

// SEE http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/Q_28145008.html

$iso_date = '2031-06-02';
$new_date = date('F j, Y', strtotime($iso_date));
echo $new_date;

Open in new window

If I'm not understanding this correctly, please post back. ~Ray
0
 
LVL 7

Author Closing Comment

by:rgranlund
ID: 39214822
Thank you for that.  It made something I'm doing much easier
0
 
LVL 109

Expert Comment

by:Ray Paseur
ID: 39214953
Thanks for the points.  Hope the article is helpful to you! ~Ray
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses how to create an extensible mechanism for linked drop downs.
Developer portfolios can be a bit of an enigma—how do you present yourself to employers without burying them in lines of code?  A modern portfolio is more than just work samples, it’s also a statement of how you work.
The viewer will learn how to count occurrences of each item in an array.
The viewer will get a basic understanding of what section 508 compliance can entail, learn about skip navigation links, alt text, transcripts, and font size controls.

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question