-3

Possible Duplicate:
Get current date and time in PHP

I was wondering how can I get the current date and time using PHP.

Community
  • 1
  • 1
HELP
  • 14,237
  • 22
  • 66
  • 100
  • 9
    Yes, that would be me. This is a hell of a basic question which you apparently haven't put the least bit of effort into. – deceze Oct 19 '10 at 05:38
  • 1
    I didn't know you had to ask COMPLEX questions on SO you get a negative `-1` for being you. – HELP Oct 19 '10 at 05:40
  • 6
    These kind of questions are so basic, you could easily answer them yourself by searching the web. Don't expect us to be your Google. – thomaux Oct 19 '10 at 05:41
  • 4
    Negative -1 == +1, so deceze will be grateful ;-) – Mischa Oct 19 '10 at 05:42
  • 3
    It's also an extremely broad question. Do you want the time formatted as a specific string? Do you want a UNIX timestamp to do calculations on? Do you want to get the day/month/year/hour/minutes as separate variables to something with? Does it need to be localized? You really don't have to ask *complex* questions, but they should at least be *specific*. Welcome to SO anyway. – deceze Oct 19 '10 at 05:50
  • 2
    Proof of concept: https://encrypted.google.com/search?hl=en&q=php+get+current+time: Have a look at the first two results. – Felix Kling Oct 19 '10 at 05:51
  • 3
    An honest question: Have you had a look in the PHP manual before? If not, why not?.... and btw. no need to become rude ok? – Felix Kling Oct 19 '10 at 06:04
  • @Deceze, there is nothing wrong with asking open questions or simple questions on SO (at least in my mind, and the minds of Jeff & Joel if you listened to the podcasts). If the stated aim of SO is to be the premier programming reference you need to have questions about how to find the date in PHP as well as the finer points of compiler optimization. And @tuff, take a chill pill mate, no matter where you go there will be people wanting to rile you up. (And directed number says that @Captaintokyo is right... a double negative is positive... @Everyone. Play nice children. This is the real world. – Tim Joseph Oct 19 '10 at 06:06
  • 1
    @Tim Joseph: The point is, that some questions are *easy* to find out by oneself... why should I take my time to help the OP if he is not willing to put *a little* effort into answering the question himself? – Felix Kling Oct 19 '10 at 06:08
  • 1
    @Felix Kling: I understand. If you can't be bothered, don't. Why bother kicking someone when they are asking for help. It is a bit like kicking a begger. They may be unlikely to sue you, but why bother (even if they do provoke you... sometimes it is difficult to understand why you get a -1, especially if you are new - which a rep of 4 would suggest!) – Tim Joseph Oct 19 '10 at 06:12
  • 3
    As you don't answer my question (*Have you had a look in the PHP manual before? If not, why not?*) I will just assume that you don't know that it exists. You can find it here: http://php.net/ It has a little search box and if you search for `time` or `date` it redirects you directly to the needed functions. The manual is a very good resource, so make use of it! (and it is probably faster than asking questions here and wait for an answer) – Felix Kling Oct 19 '10 at 06:21
  • @Tim As to why to kick somebody when they're asking for help: http://meta.stackexchange.com/questions/56817/can-we-prevent-some-of-the-low-quality-questions-from-entering-our-system – deceze Oct 19 '10 at 08:12
  • Tuff, you might find that you are a bit too sensitive for SO. How about you take a week to cool down. I deleted your colorful comments. –  Oct 19 '10 at 12:00
  • @deceze Thanks. Not sure I agree with everyones ideas, but it makes sense. I think the key is that if you `-1` someone, you explain why. We all have to learn somehow. – Tim Joseph Oct 19 '10 at 23:08

2 Answers2

12
echo time();
echo date('Y-m-d H:i:s');

http://php.net/manual/en/ref.datetime.php

deceze
  • 510,633
  • 85
  • 743
  • 889
0

The date() command (as suggested by deceze) can do all of the above

A good quick reference is http://www.wdvl.com/Authoring/Languages/PHP/Date_Time/

Tim Joseph
  • 199
  • 1
  • 2
  • 9