Hi All,
I am not sure how to change the date format in PostgreSQL. I have the dates stored in the database as - yyyy-mm-dd HH:MM:SS+TimeZone to get the GMT time (Ex: 2008-02-28 14:03:23+05:30)
. But I want these dates to be shown in the following format: - dd/mm/yyyy HH:MM:SS TimeZone (Ex: 28/02/2008 14:03:23 IST)
So now while I am trying to fetch the dates from the database I am using to_char() as below: - to_char(field_name, 'DD/MM/YYYY HH24:MI:SS TZ') AS field_name
In this way I am able to get the required format but the problem I am facing is when I am trying to use this information then I think it is treating the dates as characters so I am not able to get required result.
For Ex: When I am trying to sort the output records with the dates then it is not sorting properly.
So can anybody give some idea or example how to do this in other way and get rid of my issue.
Thanks and Regards,
Chittaranjan :)
3 24436 rski 700
Recognized Expert Contributor
Hi All,
I am not sure how to change the date format in PostgreSQL. I have the dates stored in the database as yyyy-mm-dd HH:MM:SS+TimeZo ne to get the GMT time (Ex: 2008-02-28 14:03:23+05:30). But I want these dates to be shown in the following format: dd/mm/yyyy HH:MM:SS TimeZone (Ex: 28/02/2008 14:03:23 IST). So now while I am trying to fetch the dates from the database I am using to_char() as below: to_char(field_n ame, 'DD/MM/YYYY HH24:MI:SS TZ') AS field_name
In this way I am able to get the required format but the problem I am facing is when I am trying to use this information then I think it is treating the dates as characters so I am not able to get required result.
For Ex: When I am trying to sort the output records with the dates then it is not sorting properly.
So can anybody give some idea or example how to do this in other way and get rid of my issue.
Thanks and Regards,
Chittaranjan :)
Is this -
set datestyle to 'sql,european';
-
what you are looking for?
Or you can set -
alter user username set datestyle to 'sql,european';
-
to save the setting for the next time you connect to postgres
Is this -
set datestyle to 'sql,european';
-
what you are looking for?
Or you can set -
alter user username set datestyle to 'sql,european';
-
to save the setting for the next time you connect to postgres
Hi rski,
Thanks a lot for your quick response. The examples you provided are very valuable but this is for changing the entire date style of the database tables. But I want to change the date format to European style while fetching the records from the database to show on the front end.
Please let me know if you or any one had this this kind of problem ever or the solution for this.
Your valuable responses are highly appreciated.
Thanks and Regards,
Chittaranjan :)
rski 700
Recognized Expert Contributor
Hi rski,
Thanks a lot for your quick response. The examples you provided are very valuable but this is for changing the entire date style of the database tables. But I want to change the date format to European style while fetching the records from the database to show on the front end.
Please let me know if you or any one had this this kind of problem ever or the solution for this.
Your valuable responses are highly appreciated.
Thanks and Regards,
Chittaranjan :)
Maybe write a plpgsql function like that -
create or replace function date_convert(varchar) returns date as
-
$$
-
declare
-
begin
-
execute 'set datestyle to '||'' || $1||'';
-
return now()::date;
-
end;
-
$$ language 'plpgsql'
-
and call it in php script for example -
$query="select date_convert('german')";
-
$result=pg_query($connect,$query);
-
is it helpful?
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Richard Hollenbeck |
last post by:
I'm trying to write some code that will convert any of the most popular
standard date formats twice in to something like "dd Mmm yyyy" (i.e. 08 Jan
1908) and compare the first with the second and calculate days, months, and
years. This is not for a college course. It's for my own personal
genealogy website. I'm stumped about the code. I'm working on it but not
making much progress. Is there any free code available anywhere? I know it...
|
by: Netto |
last post by:
The way PostgreSQL deals with the date format is confusing me...
I need PostgreSQL to return dates from selects at this format: "dd/mm/yyyy",
but it insists in returning it as "yyyy-mm-dd". I say "insists" cause I had
already set datestyle to "European" (in postgresql.conf) which represents
the format I want... I checked it executing: "SHOW DATESTYLE" and I got:
DateStyle
-----------
ISO with European conventions
When inserting dates,...
|
by: Franck |
last post by:
Hi,
'm gettin mad about date conversion.
Here is the point.
Got and add-in for Excel which call functions from a web service (on a
remote server)
The remote server has regional settings set to "en-UK" and date to
|
by: abcabcabc |
last post by:
I write an application which can let user define own date format to input,
How to convert the date string to date value with end-user defined date
format?
Example, User Defined Date Format as "dd/MM/yyyy"
input as "01082003" convert to date value as, 01 Aug 2003
Example, User Defined Date Format as "yyyy,dd,MM"
|
by: David Rysdam |
last post by:
I have a large amount of data that I copy in and out of Sybase very
often. Now I also want to copy this data in and out of postgres. I
have an existing script that creates the entire database(s) from scratch
in Sybase and then uses the Sybase bulk copy tool "bcp" to copy the data
in.
I already did a brute force port of this script to postgres once, but
I'm trying to do it more elegantly now that I know what issues I'm going
to run...
| |
by: somaskarthic |
last post by:
Hi
In postgresql database how to retrieve the date in a required format ? Is ther any method
to retrieve the stored date value in mm/dd/yyyy format. I don't want to set the date format in postgres databse . Whatever format the date value stored , is there any method to retrieve the date in any required format ?
Pls post your replies
Thank n advance
somas
|
by: thewilldog |
last post by:
Hello, I've reviewed the archives here to address the issue, but I'm still running into problems. I've got a table field populated with the record date in text "YYYYMMDD"
To convert it into a recognizable date format, I've done the following:
Query 1: References Source Table; Isolates Year, Day; creates MMDD field
Acc Open Year: Left(,4)
Acc Open Day: Right(,2)
MMDD: Right(,4)
Query 2: References Query 1; Isolates Month
|
by: Ashraf Ansari |
last post by:
Hi,
How Can I convert MM/dd/yyyy format into dd/MM/yyyy and the date
which is converted into dd/MM/yyyy should be in DateTime format. I do
not want to store it as a string.
Please help
Thanks in advance
|
by: thomasc1020 |
last post by:
This is regarding VB.NET 2003.
Variable 'Date' is a string and it contains date information in this
format: "DEC/05/2007".
Now I am trying to convert the format as "2007-12-05".
Is it possible to convert the arrangement using 'Format' method?
If so, please educate me how I can do such operation.
Thank you!
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |