473,506 Members | 14,630 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

PHP/MS SQL - automatic formatting: varchar, datetime

Hi,

I want to change 2 default behaviors of ms-sql server within a connection.

1. All varchar (etc.) fields should be returned as UTF-8.
I know about field attribute collation and convert function,
but I want simple query like:
SELECT * FROM table;
to return all varchars as UTF-8, no matter how the fields were
defined and which collation.

In MySQL I execute: "SET NAMES 'utf-8';" after connecting to server
In PgSQL I use native function: pg_set_client_encoding()

2. Default datetime format is sth like this: "Apr 20 2008 12:01PM"
I just want all datetimes fields were returned as:
"2008-04-20 12:01:02"
I can do that with function convert() (style=20) but I want
(as in question above) a simple query like:
SELECT * FROM table;
to return date and time formatted as described above.

In MySQL and PgSQL the format "2008-04-20 12:01:02" is the default
one.

Is it possible to do that? If yes, please tell me how can I do that?
Wladyslaw
Apr 10 '08 #1
3 6678
On Thu, 10 Apr 2008 06:31:10 +0200, W?adys?aw Bodzek
<wbodzek_nospam@poczta_nospam.onet.plwrote:

You have of course seen the topics on UTF-8 in Books Online.
Generally speaking I think most people would consider these things
part of the presentation layer (or perhaps business layer), not of the
database layer (the topic of this newsgroup).

-Tom.

>Hi,

I want to change 2 default behaviors of ms-sql server within a connection.

1. All varchar (etc.) fields should be returned as UTF-8.
I know about field attribute collation and convert function,
but I want simple query like:
SELECT * FROM table;
to return all varchars as UTF-8, no matter how the fields were
defined and which collation.

In MySQL I execute: "SET NAMES 'utf-8';" after connecting to server
In PgSQL I use native function: pg_set_client_encoding()

2. Default datetime format is sth like this: "Apr 20 2008 12:01PM"
I just want all datetimes fields were returned as:
"2008-04-20 12:01:02"
I can do that with function convert() (style=20) but I want
(as in question above) a simple query like:
SELECT * FROM table;
to return date and time formatted as described above.

In MySQL and PgSQL the format "2008-04-20 12:01:02" is the default
one.

Is it possible to do that? If yes, please tell me how can I do that?
Wladyslaw
Apr 10 '08 #2
W?adys?aw Bodzek (wbodzek_nospam@poczta_nospam.onet.pl) writes:
I want to change 2 default behaviors of ms-sql server within a connection.

1. All varchar (etc.) fields should be returned as UTF-8.
I know about field attribute collation and convert function,
but I want simple query like:
SELECT * FROM table;
to return all varchars as UTF-8, no matter how the fields were
defined and which collation.

In MySQL I execute: "SET NAMES 'utf-8';" after connecting to server
In PgSQL I use native function: pg_set_client_encoding()
There is no setting for this in SQL Server. This is something you need to
deal with client side.
2. Default datetime format is sth like this: "Apr 20 2008 12:01PM"
I just want all datetimes fields were returned as:
"2008-04-20 12:01:02"
I can do that with function convert() (style=20) but I want
(as in question above) a simple query like:
SELECT * FROM table;
to return date and time formatted as described above.

In MySQL and PgSQL the format "2008-04-20 12:01:02" is the default
one.
SQL Server returns datetime values as binary values, and it is up to
the client to format it. You will have to ask in a PHP forum how to do
that.
--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx
Apr 10 '08 #3
Usually in this situation you will find a DBA programming...

If you want to do this, simply add the functionality into the Data
abstraction layer of your programming. Why does it make a difference
how long your SELECT queries are? Either you will add the
functionality or SQL will.

On Apr 9, 11:31*pm, Władysław Bodzek
<wbodzek_nospam@poczta_nospam.onet.plwrote:
Hi,

I want to change 2 default behaviors of ms-sql server within a connection.

1. All varchar (etc.) fields should be returned as UTF-8.
* * I know about field attribute collation and convert function,
* * but I want simple query like:
* * * *SELECT * FROM table;
* * to return all varchars as UTF-8, no matter how the fields were
* * defined and which collation.

* * In MySQL I execute: "SET NAMES 'utf-8';" after connecting to server
* * In PgSQL I use native function: pg_set_client_encoding()

2. Default datetime format is sth like this: "Apr 20 2008 12:01PM"
* * I just want all datetimes fields were returned as:
* * * *"2008-04-20 12:01:02"
* * I can do that with function convert() (style=20) but I want
* * (as in question above) a simple query like:
* * * *SELECT * FROM table;
* * to return date and time formatted as described above.

* * In MySQL and PgSQL the format "2008-04-20 12:01:02" is the default
* * one.

Is it possible to do that? If yes, please tell me how can I do that?

Wladyslaw
Apr 12 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
9425
by: Gerrit Holl | last post by:
Posted with permission from the author. I have some comments on this PEP, see the (coming) followup to this message. PEP: 321 Title: Date/Time Parsing and Formatting Version: $Revision: 1.3 $...
3
146422
by: David Sharp | last post by:
I'm trying to find a way to format a FLOAT variable into a varchar in SQL Server 2000 but using CAST/CONVERT I can only get scientific notation i.e. 1e+006 instead of 1000000 which isn't really...
1
7441
by: shearichard | last post by:
Hi - I have written some python to insert a row into a table using MySQLDB. I have never before written SQL/Python using embedded parameters in the SQL and I'm having some difficulties. Could...
4
8313
by: Ken Wigle | last post by:
All, I would be very grateful for any help on this question. I have an application in asp.net 2.0 where I dynamically create a datatable and then bind that to a gridview. Unfortunately, the...
3
3465
by: SparkByte | last post by:
Now I know this has been asked before, but I am not getting the same error as mentioned in the earlier posts I could find. Server is SQL 2000 Ent. As you can see the table is for parsing...
2
3317
by: bryars | last post by:
I want to write some SQL which results in an automatic conversion of a datetime to a string in a format suitable for the Language of the connection (either by explicitly setting the Language in the...
4
1379
by: =?Utf-8?B?QW5kcmV3?= | last post by:
hi, my sp takes datetime in 'yyyyMMdd HH:mm:ss' format. however my c# datetimepicker takes 'dd/MM/yy HH:mm:ss' format. how do i convert/parse the datetime value from the datetimepicker to...
3
30768
by: Tim | last post by:
Folks, I'm trying to format a print string so that it reports progress whilst processing a looping structure with a date time stamp appended to the end of the string. This started out life as a...
1
8309
Manikgisl
by: Manikgisl | last post by:
But the problem is we have dates in Varchar instead Datetime While Converting Varchar To Datetime All four formats are unable to Convert ie select Convert(Datetime,'18-11-2008 2:35:19...
0
7308
Oralloy
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,...
1
7023
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...
0
7479
tracyyun
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...
1
5037
isladogs
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...
0
4702
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...
0
3188
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...
0
3178
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1534
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 ...
0
410
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.