Showing posts with label second. Show all posts
Showing posts with label second. Show all posts

Sunday, March 11, 2012

DateTime Format -

I have installed the trial version of windows server 2003 on the second hard drive on my computer. I set up IIS and ran my website on it but the problem is when I do something on the site, which has a sqlinsert statement regarding datetime.now it says, "conversion failed when converting datetime from character string"

I think it's to do with the clock on server 2003, the format is like: 11/07/2007 2:39:59 a.m.

I think it should be in formatAM and not a.m.

Any ideas on how to change the time format on a computer?

Or should I just change the Columns in my table to a Nvarcher value or something?

thanks

how is the value coming through? from your application? via now() ?

|||

Hi,

Thanks for your reply

What do you mean via now()?

I'm using VB and if I use something like. sqldatasource1.insertparameters.add("enddate", datetime.now()) it will give the format: 11/07/2007 2:39:59a.m.(which gives the incorrect string error.) when it should be 11/07/2007 2:39:59AM,

It must be to do with the computer clocks date time format, on server 2003 ?

Any ideas?

|||

Hi,

Please run the "Regional and Language Options" in your Control Panel. Click on "Customize", and switch to the Time tab, just to modify the "AM symbol" and "PM symbol" and hava a try.

Good Luck.

|||

store the datetime column in international format or use now.tostring("format eg. MM/dd/yyyy hh:mm:ss etc ")

|||

If the SqlDbType = DateTime then format should not come into it as the output string display is just a human readable format for display use that is not used by SQL when feeding DateTime values into it.

Do you have a snippet of the code? Something like this is what I would expect for a successful date insertion: (example routine)

public static bool InsertDateIntoRandomTable() {bool blSuccess =false;string strComm ="INSERT INTO [RandomTable] " +"(One_Date) VALUES (@.One_Date)"; SqlConnection sqlConn =new SqlConnection(strGlobalSQLConnection); SqlCommand sqlComm =new SqlCommand(strComm, sqlConn); sqlComm.Parameters.Add("@.One_Date", SqlDbType.DateTime).Value = DateTime.Now; sqlConn.Open();if (sqlComm.ExecuteNonQuery() > 0) blSuccess =true; sqlConn.Close();return blSuccess; }

Hope this helps

Mark

|||

Hi,

Thanks for the help guys

I tried what you said and it changed the clock on the computer OK. But strangley, on the website; it is still doing the format 11/11/2006 12:07a.m. instead of 11/11/2006 12:07AM

Is it something to do with IIS settings?

Thanks

|||

Hi,

After you change the time format in Regional and Language Options, you shouldrestartthe Visual Studio and open your application project, build and run the application again. Then check it and explorer the page in your IIS.

Thanks.

|||

Thanks a lot for your help. I tried restarting my computer etc. but, no luck...

Saturday, February 25, 2012

Dates not sorting properly

I am trying to sort by a date and then use a secondary sort on another column date field. The first date sorts properly, but the second is not in sorted order. I have also tried ORDER BY first date, second date and that queries the information in sorted by the first date, but then not sorted by the second date. Any ideas?

BJ

Hello BJ,

Can you post a sample of the raw data, and also, how it shows on the report?

Jarret

Friday, February 24, 2012

DatePart function in ANSI SQL

Hi folks,

How can I re-write the following code in ANSI SQL code:

select cast(datepart(month, dateadd(second, time_stamp, '1/1/1970 00:00:00')) as varchar) + '/' +
cast(datepart(day, dateadd(second, time_stamp, '1/1/1970 00:00:00')) as varchar) + '/'+ cast(datepart(year, dateadd(second, time_stamp, '1/1/1970 00:00:00')) as varchar), event_instance_id, max(time_stamp)
from usmuser.usm_sli_event_data
where event_instance_id=10019
group by cast(datepart(month, dateadd(second, time_stamp, '1/1/1970 00:00:00')) as varchar) + '/' +
cast(datepart(day, dateadd(second, time_stamp, '1/1/1970 00:00:00')) as varchar) + '/'+
cast(datepart(year, dateadd(second, time_stamp, '1/1/1970 00:00:00')) as varchar),
event_instance_id
order by event_instance_id

Thanks for your help!
-Parulcould you please explain why?

also, for those of us not patient enough to unravel the intricacies of this delectable code fragment, would you kindly please explain what it's doing|||The code should be portable so it can used be used on other databases as well, not just SQL Server.
Basically, the time_stamp field has number of seconds since 1/1/1970 and the datepart function is calculating the month, day, and year. The goal is to get the last time_stamp per event_instance_id per day.|||unfortunately, your quest will be unsatisfied

date functions are among the more un-robust of the ANSI SQL capabilities

there is practically no hope that you will get exactly the same code to run "on other databases as well, not just SQL Server"

even if we did manage to figure out a way to do what you're doing with ANSI SQL functions (and good luck to you, as i'm going to pass), it probably wouldn't run on SQL Server to start with|||This is what data abstraction layers are for...|||Thanks r937!

Friday, February 17, 2012

Datediff function

select DATEDIFF(second, min (time_stamp), max(time_stamp)) AS responsetime
FROM table1.
Now, on this table1, time_stamp column is defined in datetime format.
Case1
When the min(time_stamp) is 2/17/2005 8:34:55AM, and the max(time_stamp) is
2/17/2005 8:35:12AM ... the responsetime is shown as 0 seconds.
Case2
When the min(time_stamp) is 2/17/2005 12:00:57 PM, and the max(time_stamp)
is 2/17/2005 12:01:01 PM ... the responsetime is shown as 1 seconds.
Iam only interested in finding the difference in seconds. Can sbdy explain
me, if there is a way out ?select DATEDIFF(second, '2/17/2005 8:34:55AM', '2/17/2005 8:35:12AM')
AS responsetime1
select DATEDIFF(second, '2/17/2005 12:00:57 PM', '2/17/2005 12:01:01
PM') AS responsetime2
gives results of 17 and 4. The results you say you get, 0 and 1
are certainly not the right ones, but I've never seen DATEDIFF
give wrong results. Can you post a reproducible script that
gives these wrong results?
It looks like the min and max time_stamp values are not what you think
they are.
Steve Kass
Drew University
SQLWiz wrote:

>select DATEDIFF(second, min (time_stamp), max(time_stamp)) AS responsetime
>FROM table1.
>Now, on this table1, time_stamp column is defined in datetime format.
>Case1
>When the min(time_stamp) is 2/17/2005 8:34:55AM, and the max(time_stamp) is
>2/17/2005 8:35:12AM ... the responsetime is shown as 0 seconds.
>Case2
>When the min(time_stamp) is 2/17/2005 12:00:57 PM, and the max(time_stamp)
>is 2/17/2005 12:01:01 PM ... the responsetime is shown as 1 seconds.
>Iam only interested in finding the difference in seconds. Can sbdy explain
>me, if there is a way out ?
>|||Hi
Iam using this query:
Select log_id, track_id, DATEDIFF(second, min (time_stamp),
max(time_stamp)) AS responsetime, convert(char, min(time_stamp), 110) as
Datevalue, convert(char, min(time_stamp), 108) as timevalue
FROM xmllog_cog where time_stamp > '2005-02-16 00:00:00.000' and
track_id like 'TN-%'and log_id in(
Select distinct log_id from xmllog_cog )group by log_id, track_id
For every log_id, there can be multiple sequence ids ..(like 1,2,3 until x..
where x can vary). Each sequence id has a timestamp attached to it. Iam
interested in finding .. for every log_id what is the time difference betwee
n
1) the timestamp @. max of sequence id (lets say 11)
2) the timestamp @. min of sequence id (will always be 1).
Can you pls suggest what could be done ?
"SQLWiz" wrote:

> select DATEDIFF(second, min (time_stamp), max(time_stamp)) AS responsetim
e
> FROM table1.
> Now, on this table1, time_stamp column is defined in datetime format.
> Case1
> When the min(time_stamp) is 2/17/2005 8:34:55AM, and the max(time_stamp) i
s
> 2/17/2005 8:35:12AM ... the responsetime is shown as 0 seconds.
> Case2
> When the min(time_stamp) is 2/17/2005 12:00:57 PM, and the max(time_stamp)
> is 2/17/2005 12:01:01 PM ... the responsetime is shown as 1 seconds.
> Iam only interested in finding the difference in seconds. Can sbdy explain
> me, if there is a way out ?|||SQLWiz wrote:
> Hi
> Iam using this query:
> Select log_id, track_id, DATEDIFF(second, min (time_stamp),
> max(time_stamp)) AS responsetime, convert(char, min(time_stamp),
> 110) as Datevalue, convert(char, min(time_stamp), 108) as timevalue
> FROM xmllog_cog where time_stamp > '2005-02-16 00:00:00.000' and
> track_id like 'TN-%'and log_id in(
> Select distinct log_id from xmllog_cog )group by log_id, track_id
> For every log_id, there can be multiple sequence ids ..(like 1,2,3
> until x.. where x can vary). Each sequence id has a timestamp
> attached to it. Iam interested in finding .. for every log_id what is
> the time difference between 1) the timestamp @. max of sequence id
> (lets say 11) 2) the timestamp @. min of sequence id (will always be
> 1).
> Can you pls suggest what could be done ?
>
>
> "SQLWiz" wrote:
>
What happens when you run that query without the datediff and use MIN
and MAX as separate columns on the datetime. What values are returned?
David Gugick
Imceda Software
www.imceda.com|||See if these work - they should be equivalent,
but I didn't check them for typos:
select
T1.log_id,
T1.track_id,
datediff(second, min(T1.time_stamp), max(T1.time_stamp)) as timeDiff
from table1 as T1
where T1.sequence_id = (
select min(sequence_id)
from table1 as T2
where T2.log_id = T1.log_id
and T2.track_id = T1.track_id
)
or
T1.sequence_id = (
select max(sequence_id)
from table1 as T2
where T2.log_id = T1.log_id
and T2.track_id = T1.track_id
)
group by T1.log_id, T1.track_id
-- another way to write this that might be faster:
select
T1.log_id,
T1.track_id,
datediff(second, min(T1.time_stamp), max(T1.time_stamp)) as timeDiff
from table1 as T1
where T1.sequence_id in (
select
case when i = 1 then min(sequence_id) else max(sequence_id) end
from table1 as T2
cross join (select 1 as i union all select 2) as OneTwo
where T2.log_id = T1.log_id
and T2.track_id = T1.track_id
)
group by T1.log_id, T1.track_id
-- or this
select
T1.log_id,
T1.track_id,
datediff(second, min(T1.time_stamp), max(T1.time_stamp)) as timeDiff
from table1 as T1
join (
-- a table containing only the min and max
-- sequence_id values along with every
-- (log_id, track_id) pair you need info for
select
T.log_id,
T.track_id,
min(T.sequence_id) as min_or_max_sequence_id
from table1 as T
join xmllog_cog as X
on X.log_id = T.log_id
where <condition>
group by
T.log_id,
T.track_id
union all
select
T.log_id,
T.track_id,
max(T.sequence_id) as min_or_max_sequence_id
from table1 as T
join xmllog_cog as X
on X.log_id = T.log_id
where <condition>
group by
T.log_id,
T.track_id
) as T2
on T2.log_id = T1.log_id
and T2.track_id = T1.track_id
and T2.min_or_max_sequence_id = T1.sequence_id
-- the last condition guarantees you only get rows with
-- smallest or largest sequence_id
group by T1.log_id, T1.track_id
-- or this
select
T1.log_id,
T1.track_id,
datediff(second, min(T1.time_stamp), max(T1.time_stamp)) as timeDiff
from table1 as T1
join (
select
T.log_id,
T.track_id,
case when i = 1 then min(T.sequence_id)
else max(T.sequence_id) end
as min_or_max_sequence_id
from table1 as T
join xmllog_cog as X
on X.log_id = T.log_id
cross join (select 1 as i union all select 2) as OneTwo
where <condition>
group by
T.log_id,
T.track_id
) as T2
on T2.log_id = T1.log_id
and T2.track_id = T1.track_id
and T2.min_or_max_sequence_id = T1.sequence_id
-- the last condition guarantees you only get rows with
-- smallest or largest sequence_id
group by T1.log_id, T1.track_id
-- SK
SQLWiz wrote:
>Hi
>Iam using this query:
>Select log_id, track_id, DATEDIFF(second, min (time_stamp),
>max(time_stamp)) AS responsetime, convert(char, min(time_stamp), 110) as
>Datevalue, convert(char, min(time_stamp), 108) as timevalue
>FROM xmllog_cog where time_stamp > '2005-02-16 00:00:00.000' and
>track_id like 'TN-%'and log_id in(
>Select distinct log_id from xmllog_cog )group by log_id, track_id
>For every log_id, there can be multiple sequence ids ..(like 1,2,3 until x.
.
>where x can vary). Each sequence id has a timestamp attached to it. Iam
>interested in finding .. for every log_id what is the time difference betwe
en
>1) the timestamp @. max of sequence id (lets say 11)
>2) the timestamp @. min of sequence id (will always be 1).
>Can you pls suggest what could be done ?
>
>
>"SQLWiz" wrote:
>
>