UnitedForums - UK Web Hosting Forum UnitedHosting Community Hosting Forums
Network and Server StatusCustomer SupportUK Web Hosting
UnitedHostingUnitedHosting Sitemap UK Hosting ForumUK Web HostingWeb Hosting ForumsUK Reseller HostingWeb Host CommunityUK Managed Dedicated ServersHosting Help and SupportUK Domain Name Registration

Go Back   UnitedForums.co.uk > UnitedHosting Community > Website Development & Scripting

Reply
 
Thread Tools Rate Thread Display Modes
Old 10th January 2008, 08:08 AM   #1 (permalink)
xyz
Registered User
 
Join Date: Mar 2006
Posts: 33
MySQL DATETIME Format

Is there any way to change the default format used for DATETIME fields within the MySQL database, rather than formatting it everytime I use it.

Default format example: 2008-01-09 14:55:30

whereas I'd like: 01-09-2008 14:55:30 or even 01/09/2008 14:55:30

I've searched the documentation/forum but may have missed it as it was late last night.
xyz is offline   Reply With Quote
Old 10th January 2008, 09:28 AM   #2 (permalink)
Charles
Registered User
 
Join Date: Sep 2007
Location: 17°59′N 76°48′W
Posts: 150
Quote:
Originally Posted by xyz View Post
Is there any way to change the default format used for DATETIME fields within the MySQL database, rather than formatting it everytime I use it.

Default format example: 2008-01-09 14:55:30

whereas I'd like: 01-09-2008 14:55:30 or even 01/09/2008 14:55:30

I've searched the documentation/forum but may have missed it as it was late last night.
If you are using PHP you can pull the date from the DB and convert it and display it how you want to.
I am sure you could probably do the same with other programming languages.
Charles is offline   Reply With Quote
Old 10th January 2008, 10:01 AM   #3 (permalink)
xyz
Registered User
 
Join Date: Mar 2006
Posts: 33
Thanks for your reply Charles.

Sorry, yes I am using PHP.

I just wondered if there was a way to change the default format, so that I don't need to keep converting it. Whilst these date conversions aren't any paticular drain on performance, I am always looking at ways to reduce any extra overheads in processing that can be avoided.
xyz is offline   Reply With Quote
Old 10th January 2008, 10:05 AM   #4 (permalink)
Charles
Registered User
 
Join Date: Sep 2007
Location: 17°59′N 76°48′W
Posts: 150
Yea I ran into the same problem when I was trying to put dates into the DB.
I think you might be able to change the field structure type to Text and that might work.
Been awhile since I messed with it.
Charles is offline   Reply With Quote
Old 10th January 2008, 10:45 AM   #5 (permalink)
xyz
Registered User
 
Join Date: Mar 2006
Posts: 33
Yeah, thought about using a text field type, but then you loose the ability to sort or compare properly in your SQL query.

I'm sure there must be some way to change the default date. I'll keep on the search and post an solutions I find in this thread.

Meanwhile, if anybody else has any ideas, I'd appreciate them.

Thanks.
xyz is offline   Reply With Quote
Old 10th January 2008, 10:54 AM   #6 (permalink)
Charles
Registered User
 
Join Date: Sep 2007
Location: 17°59′N 76°48′W
Posts: 150
you can't sort a text type field? I don't see why not.
You could use 2007-01-12 (Year-Month-Day) and sort it out by the year then the month they the day.
2007-10-31
2007-12-31
2008-01-15
2008-02-23
2008-08-03

You can still order those by Assc or Desc and it would be in the correct order.
Charles is offline   Reply With Quote
Old 10th January 2008, 11:48 AM   #7 (permalink)
Terra
Registered User
 
Terra's Avatar
 
Join Date: Oct 2005
Location: old cottage
Posts: 945
DATETIME is what it is - you can't change it. But you can format the output when you pull the data from the DB.

DATETIME info: MySQL AB :: MySQL 3.23, 4.0, 4.1 Reference Manual :: 10.3 Date and Time Types

few commands I found useful: MySQL AB :: MySQL 3.23, 4.0, 4.1 Reference Manual :: 11.6 Date and Time Functions

all the best - Edith
__________________
Underground, Overground, Wombling Free!
Terra is offline   Reply With Quote
Old 10th January 2008, 12:56 PM   #8 (permalink)
xyz
Registered User
 
Join Date: Mar 2006
Posts: 33
Thanks Charles, Terra.

OK, I agree you can sort it, I was thinking about the UK format, but you can't compare two dates or use between in the SQL function if it's a text field.

Looks like I'll need to keep formatting it in the SQL query.

Thank you all again.
xyz is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off


All times are GMT. The time now is 08:27 PM.

UK Web Hosting  |  UK Reseller Hosting  |  UK Dedicated Servers UnitedHosting  |  UnitedSupport  |  UnitedForums  |  SEO by vBSEO 3.0.0
Copyright © 1998-2008 United Communications Limited. All Rights Reserved. Registered in England and Wales 3651923 - VAT Reg No. 737662309