Flins
Flins

Reputation: 221

Retrieving system date in PHP

How do I get the system date and time in this format:

$systime="12/january/2010 10.30 AM " 

Upvotes: 0

Views: 2791

Answers (4)

rekha_sri
rekha_sri

Reputation: 2725

Using date and strftime() we can get the system date.

Example:

echo date("d/F/Y g:i A");//It prints 05/March/2010 12:18 PM

echo strftime("%d/%B/%Y %I:%M %p"); //It prints  05/March/2010 12:20 PM

Upvotes: 2

Dominic Rodger
Dominic Rodger

Reputation: 99761

To get exactly what you've asked for, you'll need to use strtolower() and date:

$systime = strtolower(date("d/F/Y G.i")) . " " . date("A") . " ";

You need strtolower because there's no built-in way to get lowercase month values, so you need to get that part as January and then transform it to lowercase. You can't lowercase the whole thing because you seem to want AM or PM rather than am or pm.

Upvotes: 6

codaddict
codaddict

Reputation: 455030

Try:

$systime = date('d/F/o g i A');

Sample output:

05/March/2010 7 27 AM

Upvotes: 1

Tyler Carter
Tyler Carter

Reputation: 61567

date() and time()

Upvotes: -1

Related Questions