Jump to content

Formating Timestamp from PostgreSQL with PHP


lopes_andre

Recommended Posts

Hi,

 

I need to format a Timestamp date from PostgreSQL with PHP in Portuguese language just like this:

 

Sun, 31 Jan 2010 12:08:52

 

To show the current system date I use this function:

 

function FullDateAndTimePortuguese()
{
	setlocale(LC_ALL, NULL);
	setlocale(LC_ALL, 'pt_PT');
	$DayOfWeek = ucfirst(gmstrftime("%A %d %b %Y %H:%M", time ()));

	return $DayOfWeek;
}

 

But now I need to format the date from the database, how can I use the function?

 

If you can help me, please reply.

 

 

Best Regards,

Link to comment
Share on other sites

you'll want to do two things (if you want to use that function). the first is to modify your query to use a function that will convert your timestamp column into a UNIX timestamp:

 

SELECT date_part('epoch', timestamp_column_name) AS UNIX_timestamp FROM table

 

second, you'll need to adjust the function so that you can pass it a timestamp, rather than it assuming you want the current date/time. this involves putting a parameter in the function which has a default value when not specified:

 

function FullDateAndTimePortuguese($timestamp = time())
{
  setlocale(LC_ALL, NULL);
  setlocale(LC_ALL, 'pt_PT');
  $DayOfWeek = ucfirst(gmstrftime("%A %d %b %Y %H:%M", $timestamp));
  return $DayOfWeek;
}

 

then you can use the function to format your date and time:

 

$formatted_date = FullDateAndTimePortuguese($timestamp_from_query);

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.