Datetime, Getdate
Apr 10, 2007
Am using the getdate() function to insert dates to a table in a database, the date are inserted as for example '22/10/2006 03:05:56 AM'... I used to retrieve rows with specific dates using C# with a query like:
"SELECT * from log WHERE log_date BETWEEN '" + dtCurrentDate.String() + "' AND '" + DateTime.Now().ToString() + "'"
when I moved to VB .NET the same query returned no results, I thought this is coz VB .NET shows the same date as '10/22/2006 03:05:56 AM'
so I changed the formatting in the query but still no result
I tried use the same query in SQL Server 2005 Query Window
SELECT * FROM log WHERE log_date BETWEEN '22/10/2006 03:00:00 AM' AND '22/10/2006 04:00:00 AM'
still no result even the following query returned no result
SELECT * FROM log WHERE log_date = '22/10/2006 03:05:56 AM'
I tried to use the cast and convert functions but it couldn't convert the values between quotation to date
in the end i used the query: SELECT getdate() to see how dates are represented, the result was as for example
2006/10/22 03:05:56 AM
any help??
View 11 Replies
ADVERTISEMENT
Nov 30, 2006
I have a weird error that just started showing up. This process has run many times before and just today it started erroring.
The error I get is:
There was an error with input column "dtInsertTime" (242) on input "OLE DB Destination Input" (146). The column status returned was: "Conversion failed because the data value overflowed the specified type.".
The weird thing is that column is added to the data flow via a derived column just before the destination and its set to GETDATE(). The destination column for that field is datetime not null with the same name. I have litterally hundreds of packages that do the same thing (add a column set to getdate() of type dbtimestamp going into sql 2005 column with datetime) and have never run into this. Its frustrating.. the job will run for a half hour inserting records just fine and then BAM fails.
I'm completely out of ideas... Most destinations I don't use the fast load option so I am running it right now with that off to see if that makes a difference (other than making it slower). Previously I had it set to "keep nulls" and "table lock" but not "check integrity".
Edit: I'll have to abandon my test without fast load... my load times went from < 30 second to 2-3 minutes per set of records.
View 9 Replies
View Related
Apr 3, 2008
Here is my scenario:
I want to build a query that takes the max (or most current) DateAtMidnight from a table with all fields. This query qould ultimately be used for SSIS packages instead of formulating variables and other tables.
For simplicity, I started with a basic query.
Select DateAtMidnight, Field1, Field2
From Sales_Invoices
I cannot find a good example of how to use getdate() -1 day. Please assist.
View 4 Replies
View Related
Oct 2, 2014
When you converting varchar to date time
SELECT convert(varchar,getdate())
What is the getdate here
i.e. we are converting any value to today's date
View 9 Replies
View Related
Sep 12, 2007
For inserting current date and time into the database, is it more efficient and performant and faster to do getDate() inside SQL Server and insert the value
OR
to do System.DateTime.Now in the application and then insert it in the table?
I figure even small differences would be magnified if there is moderate traffic, so every little bit helps.
Thanks.
View 9 Replies
View Related
Oct 4, 2000
Please i need an exmple of ur solution, thanks :)
I'm using some files to show certain pages on certain date for an example
File name : aa.doc
start date: 10/02/00
end date : 10/03/00
But it expires on 10/02/00, here is the strored procedure:
Before the date comes, it expires the page
Here is my stored procedure:
"
SELECT startdate, enddate,archivedate
and (startdate is null or (getdate() >= startdate and getdate() <= enddate))
and (archivedate is null or (getdate() <= archivedate))
group by startdate, enddate order by startdate desc "
Thankx a lot
View 1 Replies
View Related
Sep 26, 2007
select convert(varchar(16), getdate(), 101)+LEFT(REPLACE(convert(varchar, getdate(), 108), ':', ''),4)
From above query I get
mmddyyyyhhmm
but it' s yyyy and hour can not be separated
04/12/200702:05
How can I separated the year and hour ?
Thanks
Daniel
View 2 Replies
View Related
Jul 9, 2007
Hi,
I'm inserting a datetime values into sql server 2000 from c#
SQL server table details
Table nameate_test
columnname datatype
No int
date_t DateTime
C# coding
SqlConnection connectionToDatabase = new SqlConnection("Data Source=.\SQLEXPRESS;Initial Catalog=testdb;Integrated Security=SSPI");
connectionToDatabase.Open();
DataTable dt1 = new DataTable();
dt1.Columns.Add("no",typeof(System.Int16));
dt1.Columns.Add("date_t", typeof(System.DateTime));
DataRow dr = dt1.NewRow();
dr["no"] = 1;
dr["date_t"] = DateTime.Now;
dt1.Rows.Add(dr);
for(int i=0;i<dt1.Rows.Count;i++)
{
string str=dt1.Rows["no"].ToString();
DateTime dt=(DateTime)dt1.Rows["date_t"];
string insertQuery = "insert into date_test values(" + str + ",'" + dt + "')";
SqlCommand cmd = new SqlCommand(insertQuery, connectionToDatabase);
cmd.ExecuteNonQuery();
MessageBox.Show("saved");
}
When I run the above code, data is inserted into the table
The value in the date_t column is 2007-07-09 22:10:11 000.The milliseconds value is always 000 only.I need the millisecond values also in date_t column.
Is there any conversion needed for millisecond values?
thanks,
Mani
View 3 Replies
View Related
Dec 6, 2006
I'm getting error:
String was not recognized as a valid DateTime.
my insert parameter:
<asp:Parameter Name="LastModified" Type="DateTime" DefaultValue= "<%=DateTime.Now.ToString() %>"
my insert command:
InsertCommand="INSERT INTO [Product] ([Enabled], [ProductCode], [ProductName], [ProductAlias], [CarrierId], [DfltPlanId], [DoubleRating], [DoubleRateProductId], [ConnCharges], [StartDate], [EndDate], [Contracted], [BaseProductId], [LastModified], [LastUser]) VALUES (@Enabled, @ProductCode, @ProductName, @ProductAlias, @CarrierId, @DfltPlanId, @DoubleRating, @DoubleRateProductId, @ConnCharges, @StartDate, @EndDate, @Contracted, @BaseProductId, @LastModified, @LastUser)"
LastModified is a datetime field.
Running sql2005
View 1 Replies
View Related
Mar 14, 2007
Hi all, having a little problem with saving dates to sql databaseI've got the CreatedOn field in the table set to datetime type, but every time i try and run it i get an error kicked up Error "The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value.The statement has been terminated."I've tried researching it but not been able to find something similar. Heres the code: DateTime createOn = DateTime.Now;string sSQLStatement = "INSERT INTO Index (Name, Description, Creator,CreatedOn) values ('" + name + "','" + description + "','" + userName + "','" + createOn + "')"; Any help would be much appreciated
View 4 Replies
View Related
Mar 17, 2007
Hey :)I'm facing a lot of troubles trying to create a new pause/break-system. Right now i'm building up the query that counts how many records that is inside 2 fields. Let me first show you my table:
ID (int) | stamp_start (Type: DateTime) | stamp_end (Type: DateTime) | Username (varchar)0 | 17-03-07 12:00:00 | 17-03-07 12:30:00 | Hovgaard
The client will enter a start time and a end time and this query should then count how many records that are inside this periode of time.
Example: The client enter starttime: 12:05 and endtime: 12:35.The query shall then return 1 record found. The same thing if the user enters 12:20 and 12:50.My current query looks like this:SELECT COUNT(ID) AS Expr1 FROM table WHERE (start_stamp <= @pausetime_start) AND (end_stamp >= @pausetime_end)But this will only count if I enter the exact same times as the one inside the table.Any ideas how I can figure this out?Thanks for your time so far :)/Jonas Hovgaard - Denmark
View 2 Replies
View Related
May 13, 2006
Hi,
I have a column of type datetime in sqlserver 2000. Whenever I try to insert the date
'31/08/2006 23:28:59'
I get the error "...datetime data type resulted in an out-of-range datetime value"
I've looked everywhere and I can't solve the problem. Please note, I first got this error from an asp.net page and in order to ensure that it wasn't some problem with culture settings I decided to run the query straight in Sql Query Anaylser. The results were the same. What else could it be?
cheers,
Ernest
View 2 Replies
View Related
Mar 11, 2014
I am inserting date and time data into a SQL Server 2012 Express table from an application. The application is providing the date and time as a string data type. Is there a TSQL way to convert the date and time string to an SQL datetime date type? I want to do the conversion, because SQL displays an error due to the
My date and time string from the application looks like : 3/11/2014 12:57:57 PM
View 1 Replies
View Related
Sep 7, 2007
Nothing difficult, I just need a way to generate a new datetime column based on the column [PostedDate], datetime. So basically I want to truncate the time. Thanks a lot.
View 5 Replies
View Related
Jan 17, 2008
e.g.
1st March 2005 12:00:00
is showing as
01/03/2005 00:00:00
instead of
01/03/2005
Why does this happen?
View 4 Replies
View Related
May 13, 2008
When I use the getDate() function I get something like
2005-03-09 15:13:45.017
but I don't want the time, just 2005-03-09
how do you strip out the time from the result?
Thanks
View 2 Replies
View Related
May 28, 2008
How can i getdate in C# code, like we do in SQL Server ?
Thanks.
View 1 Replies
View Related
Apr 27, 2001
However, when I run select getdate() in Sql 6.5 I get the following
Apr 27 2001 11:59AM
Both queries are run from the QueryIsql window.
How can I get the sql 7 version of getdate to be exactly the same as the
sql 6.5 version from the query window without resorting to usign the
convert function?
According to Sql 7 books online, getdate
"Returns the current system date and time in the Microsoft® SQL Server™ standard internal format for datetime values"
View 1 Replies
View Related
Oct 3, 2000
I'm facing some strange problem here:
-----------------------------------------
I'm using some files to show certain pages on certain date for an example
File name : aa.doc
start date: 10/02/00
end date : 10/03/00
But it expires on 10/02/00, here is the strored procedure:
Before the date comes, it expires the page
Here is my stored procedure:
"
SELECT startdate, enddate,archivedate
and (startdate is null or (getdate() >= startdate and getdate() <= enddate))
and (archivedate is null or (getdate() <= archivedate))
group by startdate, enddate order by startdate desc "
Thankx a lot
View 2 Replies
View Related
Sep 20, 2000
i am also trying to write a query that
retrieve information on yesterdays new registered
member. So far as i am concern with sqlserver you use
the getdate()-1 to retrieve this information. But the
problem i get when i try to use the getdate()-1 is
that i tend to get todays and yesterdays registered
users. Is there anywhere that i would be able to
retrieve information on just yesterdays new registered
members and also only todays new register members.
View 1 Replies
View Related
Sep 28, 2000
The following WHERE clause does not generate a datetime from my GETDATEs. Can anyone help me out on the syntax?
WHERE (FROMTIME = GETDATE() AND ToTime = GETDATE())
Thanks much.
TM
View 7 Replies
View Related
Aug 7, 2003
Is it right, that getdate() cannot be used in an user defined function. if so, then how do i get hte current date and time in my function?
View 2 Replies
View Related
May 19, 2005
Hi
I know this is going to sound really daft, but what is the easiest way of getting today's date without the time? Getdate() on it's own doesn't work because it always brings out the time. I know I'm missing something really basic but I can't figure it out.
Please help.
Thanks
View 3 Replies
View Related
Aug 17, 2005
How to get the first and last day of the previous month using function getDate()?
View 2 Replies
View Related
Oct 20, 2004
G'day,
I want to display the current time minus 5 minutes. say
2004-03-29 11:43:49.123 to be 2004-03-29 11:38:49.123.
Is there any Equivalent to the DB2's CURRENT TIMESTAMP - 5 MINUTES which will display the current day say 2004-03-29 11:43:49.123 as
2004-03-29 11:38:49.123
cheers
Melb
View 2 Replies
View Related
May 19, 2006
I'm using getdate() - 74 and getting something like
2006-03-06 11:26:02.870
Is there a simple way to get
2006-03-06 00:00:00.000
instead?
Or just get the date and not the time part. I'm using this date with a between function and the time component is throwing it off.
I'm using
cast(convert(char, getdate(),112) as datetime) - 74
and it works...but there must be an easier way...
View 6 Replies
View Related
Feb 10, 2007
Hi,
when I used getdate() fuction, its giving the correct time in this format 10/02/2007 01:04:31 PM. But I need the time in 24 hour format. Means it should be like 10/02/2007 13:04:31.
How to get it. Please help me!!
shaji
View 5 Replies
View Related
May 21, 2007
select
H.IsoDate,
HI.Country,
HI.Center,
H.ExchangeCode,
HC.Holiday,
H.HolidayCode
from
Holidays H
join
HolidayInfo HI
on
HI.Code = H.ExchangeCode
join
HolidayCodes HC
on
H.HolidayCode = HC.Code
where
H.isodate = getdate()
This is a script but the getdate part is not working can somebody point me in the right direction where i might be going wrong.
The date format in H.isodate is like this:
2005-06-24 00:00:00.000
cheers in advance
View 2 Replies
View Related
Dec 27, 2007
Hello,
I'm new to SQL server and I'm trying to insert the system time into a table.
I'm using following insert statement. But I get an error 'incorrect syntax near the keyword select'
INSERT INTO today(datum) VALUES(SELECT getdate() FROM today)
The datatype of datum is Datetime
Can someone please tell me what I'm doing wrong
Thanks
View 1 Replies
View Related
Mar 13, 2008
I am setting up a table and I want to capture the creation date of each record when it comes in. Obviously the easy way to do this is set the dfault value of this field to getdate(), but I am wondering if there is a benefit to using an insert trigger instead?
I will also be adding a seperate updatedOn field and plan to use an update trigger to populate it. If there is a better way to do either of these please let me know.
View 3 Replies
View Related
Mar 13, 2008
Folks:
I use,
PRINT CONVERT(VARCHAR, GETDATE())
To write the current date to the console (for debugging purposes). Only problem is it only shows hours and minutes (not seconds). Can anyone suggest an equivalent that shows seconds as well?
View 1 Replies
View Related
Mar 27, 2007
Hi if i in a table using getdate then
the field get the date from the Machine this is all right
But when i use getdate in my Query then i get Zerro records Why?
Alvin
View 6 Replies
View Related
Jun 15, 2004
I have the following SQL:
select convert(datetime,'04-20-' + right(term,4)) as dt,
'Deposit' as type, a.* from
dbo.status_view a
where right(term,4) always returns a string which constitutes a 4 digit year eg '1999','2004',etc.
The SQL above returns
2004-04-20 00:00:00.000 Deposit ...
Which makes me think that it is able to successfully construct the datetime object inline. But then when I try and do:
select * from
(
select convert(datetime,'04-20-' + right(term,4)) as dt,
'Deposit' as type, a.* from
dbo.status_view a
) where dt >= a.submit_date
I get the following error:
Syntax error converting datetime from character string.
Given that it executes the innermost SQL just fine and seems to convert the string to a datetime object, I don't see why subsequently trying to USE that datetime object for something (in this case comparison with submit_date which is a datetime in the table a) should screw it up. Help!!! Thanks...
View 6 Replies
View Related