|
INTERVIEW QUESTIONS
PROGRAMMING LANGUAGES
PHP
DETAILS
Question: If you have to work with dates in the following format: "Tuesday, February 14, 2006 @ 10:39 am", how can you convert them to another format, that is easier to use?
Answer: The strtotime function can convert a string to a timestamp. A timestamp can be converted to date format. So it is best to store the dates as timestamp in the database, and just output them in the format you like.
So let's say we have $date = "Tuesday, February 14, 2006 @ 10:39 am"; In order to convert that to a timestamp, we need to get rid of the "@" sign, and we can use the remaining string as a parameter for the strtotime function.
So we have $date = str_replace("@ ","",$date); $date = strtotime($date);
now $date is a timestamp and we can say:
echo date("d M Y",$date);
|
|
|
Category |
PHP Interview Questions & Answers -
Exam Mode /
Learning Mode
|
Rating |
(0.3) By 8210 users |
Added on |
7/19/2011 |
Views |
72107 |
Rate it! |
|
|
Question:
If you have to work with dates in the following format: "Tuesday, February 14, 2006 @ 10:39 am", how can you convert them to another format, that is easier to use?
Answer:
The strtotime function can convert a string to a timestamp. A timestamp can be converted to date format. So it is best to store the dates as timestamp in the database, and just output them in the format you like.
So let's say we have $date = "Tuesday, February 14, 2006 @ 10:39 am"; In order to convert that to a timestamp, we need to get rid of the "@" sign, and we can use the remaining string as a parameter for the strtotime function.
So we have $date = str_replace("@ ","",$date); $date = strtotime($date);
now $date is a timestamp and we can say:
echo date("d M Y",$date); Source: CoolInterview.com
If you have the better answer, then send it to us. We will display your answer after the approval.
Rules to Post Answers in CoolInterview.com:-
- There should not be any Spelling Mistakes.
- There should not be any Gramatical Errors.
- Answers must not contain any bad words.
- Answers should not be the repeat of same answer, already approved.
- Answer should be complete in itself.
|
|
Related Questions |
View Answer |
|
How do we know browser properties?
|
View Answer
|
|
How i will check that user is, logged in or not. i want to make it a function and i want to use in each page and after login i want to go in current page(same page. where i was working)
|
View Answer
|
|
How can i get ip address?
|
View Answer
|
|
What is difference between mysql_connect and mysql_pconnect
|
View Answer
|
|
What is the difference between echo and print statement?
|
View Answer
|
|
How i can make a chat page in php in simple
|
View Answer
|
|
What is difference between mysql_fetch_array(),mysql_fetch_row() and mysql_fetch_object() please insert with example.
|
View Answer
|
|
How can I maintain the count of how many persons have hit my site?
|
View Answer
|
Please Note: We keep on updating better answers to this site. In case you are looking for Jobs, Pls Click Here Vyoms.com - Best Freshers & Experienced Jobs Website.
View All PHP Interview Questions & Answers - Exam Mode /
Learning Mode
|