Showing posts with label datefield. Show all posts
Showing posts with label datefield. Show all posts

Friday, February 24, 2012

Dates

trying to create a stored proc with this query:
select * from table1 where datefield BETWEEN @.startdate
AND @.enddate.
When using Crystal reports against this,it works fine
except when you are just using one day- for example your
start date and end date would both be 9/2/2004. Anyone run
into this? Should I do something different? THANKS!probably you are not considering time component. See following example.
create table t(dt datetime)
insert into t values ('20040903 12:24:15')
insert into t values ('20040903 1:24:15')
insert into t values ('20040903 16:24:15')
insert into t values ('20040903')
insert into t values ('20040904')
select * from t
where dt between '20040903' and '20040903 23:59:59'
Vishal Parkar
vgparkar@.yahoo.co.in | vgparkar@.hotmail.com
"Ann" <anonymous@.discussions.microsoft.com> wrote in message
news:51bb01c49134$9db6b420$a501280a@.phx.gbl...
> trying to create a stored proc with this query:
> select * from table1 where datefield BETWEEN @.startdate
> AND @.enddate.
> When using Crystal reports against this,it works fine
> except when you are just using one day- for example your
> start date and end date would both be 9/2/2004. Anyone run
> into this? Should I do something different? THANKS!

daterange problem

Hi all

I am using Crystal reports 8.5 and SQL Server

i am littlebit confused in writing formula giving you the scenario :

in one table i have datefield
need to check that date falls under the given date range

(ex: given date range :09/12/2005 - 02/11/2006

field consists : 13/12/2005

like above i need the count of the fields which falls under that date range

please help meuse formula something like this
if '2-jan-2006' > '1-jan-2006' or '2-jan-2006' < '31-jan-2006' then
1
else
0

then use summary function sum.

hope it helps|||Thanks its helps for me

Another problem is there with date range

when i selects a startdatetime from daterange,it should go back to one year and fixes to date and month (i.e May 31)

startdatetime -- 03/04/2006

date should goes to -- 05/31/2005

i used dateadd('yyyy',-1, startdatetime) it is decreasing one year but i am unable to fix the date to May 31

thank you very much|||if date is fixed to 31-may then u can use this formula

left(cstr('31-may-'& val(right(cstr(cdate('8-jan-2006')),4))-1),11)|||Thank you very much

you showed me away to do this

thanks a lot|||Hi

when i used your formula

getting the value like 2,005

Actually my aim to take this as daterange instead of actual date range

so if it contains "," unable to take it as daterange

pls help me|||I don't see anyproblem in that formula except its returning a string.

can you write how, u r using that formula|||Hi,

I am using what u r send formula.
But i get comma oerator in the year.

i am using like this
'31/1/'+ cstr(val(right(cstr(cdate('8/1//2006')),4))-1)

i am getting
31/1/2,005|||Hi,

I am using what u r send formula.
But i get comma oerator in the year.

i am using like this
'31/1/'+ cstr(val(right(cstr(cdate('8/1//2006')),4))-1)

i am getting
31/1/2,005

i removed one slash from between 1//2006

put as a formula
'31/1/'+ cstr(val(right(cstr(cdate('8/1/2006')),4))-1)
and got my output as

31/1/2005.00|||Hi

Thanks for your reply

In the given date range i am getting some customer ids from database

what i want is need to check whether those customer ids are existing or not in the perticular date range(i.e different date range from given date range)

if i am getting customer ids for this date range (07/01/2005 - 07/31/2005)

need to check the customer ids are existing in tthis date range(06/01/2005 - 06/30/2005)

could you pls help me|||iam developing the crystal report there was small problem iam facing

please help me

How to use parameter of main report into the subreport

example

@.startdatetime is a parameter in main report
ia want to use the same parmeter in subreport

Tuesday, February 14, 2012

DateAdd function in Stored Procedure

I need to be able to store a value in a datefield that is 8 hours greater
than another datefield (SchedOpen) which the user updates. What happens is
the user enters local time and I need to also store that time as GMT. I trie
d
this as an alias in a stored procedure: "DATEADD(hh, 8, SchedOpen)" and it
works fine until there is a time when adding 8 hours goes beyond midnight. I
then get a date added to the field which is the year 1900. I suspect that
since the field only contains time the date is defaulted to 1900. There is a
date field in each row with the current date so I need to somehow add that t
o
the GMT field before adding the 8 hours but I just can't figure out how to
do this. Any Ideas? Thanks.Why you need to store it.
you still can access the same field and add the extra 8 hours.
I don't see a problem in adding the hours.
your problem is how to format the date field.
I tried this one
select getdate(),dateadd(hh,8,getdate())
the result was:-
2005-12-07 16:55:13.197 2005-12-08 00:55:13.197
So you can see that I passed the midnight and the and became in a new day.
I still can access the time or the date portions by formating the date.
like in this example:-
select convert(char(8),getdate(),8),convert(cha
r(8),dateadd(hh,8,getdate()),
8)
the result was
17:06:27 01:06:27
I got what I need from the date and i added the hours too.
So all about formating the date.
Thanks,
Nader Shahin
"AkAlan" wrote:

> I need to be able to store a value in a datefield that is 8 hours greater
> than another datefield (SchedOpen) which the user updates. What happens is
> the user enters local time and I need to also store that time as GMT. I tr
ied
> this as an alias in a stored procedure: "DATEADD(hh, 8, SchedOpen)" and i
t
> works fine until there is a time when adding 8 hours goes beyond midnight.
I
> then get a date added to the field which is the year 1900. I suspect that
> since the field only contains time the date is defaulted to 1900. There is
a
> date field in each row with the current date so I need to somehow add that
to
> the GMT field before adding the 8 hours but I just can't figure out how t
o
> do this. Any Ideas? Thanks.
>|||AkAlan (AkAlan@.discussions.microsoft.com) writes:
> I need to be able to store a value in a datefield that is 8 hours
> greater than another datefield (SchedOpen) which the user updates. What
> happens is the user enters local time and I need to also store that time
> as GMT. I tried this as an alias in a stored procedure: "DATEADD(hh, 8,
> SchedOpen)" and it works fine until there is a time when adding 8 hours
> goes beyond midnight. I then get a date added to the field which is the
> year 1900. I suspect that since the field only contains time the date is
> defaulted to 1900. There is a date field in each row with the current
> date so I need to somehow add that to the GMT field before adding the 8
> hours but I just can't figure out how to do this. Any Ideas? Thanks.
There is no time data type in SQL Server (not even in SQL 2005). When you
do not specify a date, the default date is 1900-01-01.
If you want to keep all times within the same date, you will have to
something like:
SELECT convert(datetime, convert(char(8), dateadd(hh, 8, SchedOpen), 108))
or
SELECT dateadd(hh, CASE WHEN SchedOpen < '16:00:00' THEN 8 ELSE -16 END,
SchedOpen)
By the way, in most interfaces you will have to explicitly remove that
date part of 1900-01-01. You may be looking in Enterprise Manager, but
EM is not an application.
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se
Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pr...oads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodin...ions/books.mspx|||Thanks, I did figure out how to add the date field with the time field like
this:
DATEADD(hh, 9, dbo.tblMissions.DateFlown + dbo.tblMtr.StartTime)
This allows me to format the field and present it the way the customer
wants. My real problem is storing the data without have to make design
changes every time we change daylight savings time. I'm using MS Access as
a
front end. Here is the situation...I have a form which the user enters a
local date and time value. I need the report to display the local values as
well as the corresponding GMT based on the local entry. I need to store the
GMT value with each row since I never know on which day the data is being
viewed. I think I'll have to ceate a table and add the daylight savings days
(beging and end) then check the entry date to the table and update the field
with code on the after update event of the local time field. Thanks for your
reply.
"Nader Shahin" wrote:
> Why you need to store it.
> you still can access the same field and add the extra 8 hours.
> I don't see a problem in adding the hours.
> your problem is how to format the date field.
> I tried this one
> select getdate(),dateadd(hh,8,getdate())
> the result was:-
> 2005-12-07 16:55:13.197 2005-12-08 00:55:13.197
> So you can see that I passed the midnight and the and became in a new day.
> I still can access the time or the date portions by formating the date.
> like in this example:-
> select convert(char(8),getdate(),8),convert(cha
r(8),dateadd(hh,8,getdate()
),8)
> the result was
> 17:06:27 01:06:27
> I got what I need from the date and i added the hours too.
> So all about formating the date.
> Thanks,
> Nader Shahin
>
> "AkAlan" wrote:
>