Showing posts with label datetime. Show all posts
Showing posts with label datetime. Show all posts

Tuesday, March 6, 2012

about the type field : datetime and smalldatetime

hi all,
the field type :datetime and smalldatetime, i still can't understand.
everytime when i inserted the data to the db, i also get the error message"System.Data.SqlClient.SqlException: The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value."
i must change the field type tostring, so that i can insert data
my code
txt_datetime.text = '5/2/2006'
insert into datetime (datetime) values ('"& txt_datetime.text & "')"

can anybody tell me the reason?

thank you!!In your SQL statement:

insert into datetime (datetime) values ('"& txt_datetime.text & "')"

Is your table named datetime? Isn't that a keyword? If that's not the problem, then can you post the source code where you are inserting the value?|||

What culture is your SQL Server running under?

I'm guessing this statement will fail as well:

SELECT CAST('5/2/2006' as datetime)

Try running that as a query.

But beyond that... Stop generating SQL Statements by using string concatenation and your problem will go away.

dim conn as new sqlconnection("{Connection string}")
conn.open
dim cmd as new sqlcommand("INSERT INTO [datetime](datetime) values (@.datetime)",conn)
cmd.parameters.add("@.datetime",sqldbtype.datetime).value='5/2/2006'
cmd.executenonquery
conn.close

|||

hi all,

first at all, thank you for reply
now i solved the problem and i think i know the reason, because the sql server and .net software are in difference language , sql server is tradition chinese version and .net software is in english version . the field type - datetime in sql server (english version ) is "dd/mm/yyyy" but in chinese is "mm/dd/yyyy" and when i insert the data to the db via the .net application, the datetime format is"dd/mm/yyyy", so i have to splite the datatime string and change it to "mm/dd/yyyy".

hijcasp,
my table name is called paper and the field name is deadline.
txt_deadline.text = '5/2/2006'
dim deadline_array = splite(txt_deadline.text, "/")
dim deadline as string
deadline = deadline_array.(1) & "/" & deadline_array(0) & "/" & deadline_array(2)
"insert into paper(deadline) values(" & deadline & ")"

hi,Motley
"Stop generating SQL Statements by using string concatenation ", why i should stop to use concatenation??

|||

1) Because you run into problems like the one you mentioned.

2) Because string concatenating sql strings will suffer from SQL Injection attacks if you aren't really careful.

3) Performance.

4) Portability.

5) Maintanability.

6) Readability.

If at a later time you decide to change the SQL Server culture, your code breaks. If you decide to change your .NET culture, your code breaks. If you decide you want to localize your application to multiple cultures, your code breaks. The code I gave you runs no matter what culture your .NET appliction is, or what culture your SQL Server is, and runs faster and demands less resources of the SQL Server making it more scalable.

Just as a point of clarification, the issue wasn't that the language was different, it's that the culture formats of the .NET application and the SQL Server were different. The date format for en-US (English in the United States) is mm/dd/yy. The date format for en-GB (English in Great Britian) is dd/mm/yy. You had the right idea on the cause, just not the correct term. Cultures are made up of a language and a locale. The language part of the culture wasn't the problem, it's the locale part that determines what format dates, times, numbers, currency are in, and that's the part that caused you the problem.

Sunday, February 19, 2012

About removal of TimeStamp from DateTime part in TSQL.

Hi friends,
Does anybody could say how to remove the TimeStamp from DateTime part
in TSQL.
Thanks&Regards
Sunil.
Sunil a crit :
> Hi friends,
> Does anybody could say how to remove the TimeStamp from DateTime part
> in TSQL.
> Thanks&Regards
> Sunil.
>
Example, actual date without time :
SELECT CAST(FLOOR(CAST(CURRENT_TIMESTAMP AS FLOAT)) AS DATETIME) AS
"CURRENT_DATE"
CURRENT_DATE
2006-02-15 00:00:00.000
A +
Frdric BROUARD, MVP SQL Server, expert bases de donnes et langage SQL
Le site sur le langage SQL et les SGBDR : http://sqlpro.developpez.com
Audit, conseil, expertise, formation, modlisation, tuning, optimisation
********************* http://www.datasapiens.com ***********************
|||Removing is not possible if you use a timestamp, though you can set it
to 00:00:00, but eleminating is NOT possible. Time is always stuck to
date and vice versa. If you want the two things separated, you have to
use a CHARACTER Storage like VARCHAR, then you can CONVERT the datetime
to any non-containing time-format.
HTH, jens Suessmeyer.
|||Hi
The time part of a datetime will always be stored in the database, even if
you do not specify it when you insert the date it will default the time to
00:00:00. For display purposes you can use the CONVERT function to display
only the date portion of the datetime in a string format. See Books Online
for more information.
John
"Sunil" wrote:

> Hi friends,
> Does anybody could say how to remove the TimeStamp from DateTime part
> in TSQL.
> Thanks&Regards
> Sunil.
>

About removal of TimeStamp from DateTime part in TSQL.

Hi friends,
Does anybody could say how to remove the TimeStamp from DateTime part
in TSQL.
Thanks&Regards
Sunil.
http://www.karaszi.com/SQLServer/inf...dOfTimePortion
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
Blog: http://solidqualitylearning.com/blogs/tibor/
"Sunil" <nsunildutt@.gmail.com> wrote in message
news:1140016409.964263.61880@.f14g2000cwb.googlegro ups.com...
> Hi friends,
> Does anybody could say how to remove the TimeStamp from DateTime part
> in TSQL.
> Thanks&Regards
> Sunil.
>
|||Thanks all .
Tibor provided an excellent link.
|||Thanks all .
Tibor provided an excellent link.

About removal of TimeStamp from DateTime part in TSQL.

Hi friends,
Does anybody could say how to remove the TimeStamp from DateTime part
in TSQL.
Thanks&Regards
Sunil.http://www.karaszi.com/SQLServer/info_datetime.asp#GettingRidOfTimePortion
--
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
Blog: http://solidqualitylearning.com/blogs/tibor/
"Sunil" <nsunildutt@.gmail.com> wrote in message
news:1140016409.964263.61880@.f14g2000cwb.googlegroups.com...
> Hi friends,
> Does anybody could say how to remove the TimeStamp from DateTime part
> in TSQL.
> Thanks&Regards
> Sunil.
>|||Thanks all .
Tibor provided an excellent link.|||Thanks all .
Tibor provided an excellent link.

About removal of TimeStamp from DateTime part in TSQL.

Hi friends,
Does anybody could say how to remove the TimeStamp from DateTime part
in TSQL.
Thanks&Regards
Sunil.Sunil a écrit :
> Hi friends,
> Does anybody could say how to remove the TimeStamp from DateTime part
> in TSQL.
> Thanks&Regards
> Sunil.
>
Example, actual date without time :
SELECT CAST(FLOOR(CAST(CURRENT_TIMESTAMP AS FLOAT)) AS DATETIME) AS
"CURRENT_DATE"
CURRENT_DATE
---
2006-02-15 00:00:00.000
A +
Frédéric BROUARD, MVP SQL Server, expert bases de données et langage SQL
Le site sur le langage SQL et les SGBDR : http://sqlpro.developpez.com
Audit, conseil, expertise, formation, modélisation, tuning, optimisation
********************* http://www.datasapiens.com ***********************|||Removing is not possible if you use a timestamp, though you can set it
to 00:00:00, but eleminating is NOT possible. Time is always stuck to
date and vice versa. If you want the two things separated, you have to
use a CHARACTER Storage like VARCHAR, then you can CONVERT the datetime
to any non-containing time-format.
HTH, jens Suessmeyer.|||Hi
The time part of a datetime will always be stored in the database, even if
you do not specify it when you insert the date it will default the time to
00:00:00. For display purposes you can use the CONVERT function to display
only the date portion of the datetime in a string format. See Books Online
for more information.
John
"Sunil" wrote:
> Hi friends,
> Does anybody could say how to remove the TimeStamp from DateTime part
> in TSQL.
> Thanks&Regards
> Sunil.
>

About removal of TimeStamp from DateTime part in TSQL.

Hi friends,
Does anybody could say how to remove the TimeStamp from DateTime part
in TSQL.
Thanks&Regards
Sunil.http://www.karaszi.com/SQLServer/in...idOfTimePortion
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
Blog: http://solidqualitylearning.com/blogs/tibor/
"Sunil" <nsunildutt@.gmail.com> wrote in message
news:1140016409.964263.61880@.f14g2000cwb.googlegroups.com...
> Hi friends,
> Does anybody could say how to remove the TimeStamp from DateTime part
> in TSQL.
> Thanks&Regards
> Sunil.
>|||Thanks all .
Tibor provided an excellent link.|||Thanks all .
Tibor provided an excellent link.

Saturday, February 11, 2012

About DateTime in SQL

Hi,
I am making a report in SQL Reporting with the following format.
Does any have any idea how can I get date in this format "Monday, March 26, 2007" and how can I get time of each tranction in Reporting.I tried Formatdatetime function but it doesn't work..Plzz help me Thanks

Monday, March 26, 2007
10am 100
10am 110
1pm 100
Total: 310
Tuesday,March 27,2007
11am 500
6 pm 500
Total: 1000
Grad Total 1310

Quote:

Originally Posted by ri58776

Hi,
I am making a report in SQL Reporting with the following format.
Does any have any idea how can I get date in this format "Monday, March 26, 2007" and how can I get time of each tranction in Reporting.I tried Formatdatetime function but it doesn't work..Plzz help me Thanks

Monday, March 26, 2007
10am 100
10am 110
1pm 100
Total: 310
Tuesday,March 27,2007
11am 500
6 pm 500
Total: 1000
Grad Total 1310


----
For Date format you can use....Example,

SELECT substring(CONVERT(CHAR(20),'March 26, 2007 05:32:08 PM',109),1,14)

For Time part... Example
SELECT CONVERT(CHAR(15),'05:32:08 PM',114)

about datetime

I have to convert date such as '2006-09-21 13:27:25.077' to '20060921'

any ideas?

thanks in advance

I attempted to convert(char(8),getdate()),but result is 'Sep 21...'

I have no idea about that

|||

Problem solved!

datatime have many styles

just like convert(char(8),getdate(),112) can perform what i want