lopes_andre Posted January 31, 2010 Share Posted January 31, 2010 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, Quote Link to comment Share on other sites More sharing options...
akitchin Posted January 31, 2010 Share Posted January 31, 2010 what is the timestamp's format in PostgreSQL? is it a UNIX timestamp, or is it in a format like YYYY-MM-DD HH:MM:SS? Quote Link to comment Share on other sites More sharing options...
lopes_andre Posted January 31, 2010 Author Share Posted January 31, 2010 Hi, Thanks for the reply. The format is YYYY-MM-DD HH:MM:SS. Best Regards, Quote Link to comment Share on other sites More sharing options...
akitchin Posted January 31, 2010 Share Posted January 31, 2010 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); Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.