Elegant Way To Strip Off Date From Datetime?
Dec 24, 2007
if all I want is 12am of the date provided in a datetime column, is there a more elegant way of doing this than something like...
convert (datetime,
convert(varchar(2), month([time])) + '/' +
convert(varchar(2), day([time])) + '/' +
convert(varchar(4), year([time]))
)
View 1 Replies
ADVERTISEMENT
Dec 10, 2007
if your employee rows are all versioned with an effective date, and specific employee records can have more than 1 row, is there a more elegant/efficient way of snagging the correct employee rows than...
select * from [dbo].employee a where a.effDate in
(select max(b.effDate) from [dbo].employee b where b.employId = a.employId and
b.effDate <= @parmDate)
...not worrying about end dates for now, and also not worrying about duplicate eff dates for same employee id and assuming @parmDate is a passed "as of date"?
View 6 Replies
View Related
Jan 18, 2005
I would like something I can do inline eg:
select convert(blahdatatype,a.datefield) as smallerdatefield
from
a
where a.datefield is a datetime. If a contains rows like:
datefield
---------------------
01/20/2005 22:17:23
08/23/2001 03:04:15
...
Then the SQL above returns:
smallerdatefield
---------------------
01/20/2005 00:00:00
08/23/2001 00:00:00
...
Is there any non-obnoxious way (eg: without have to result to using datepart a million times) to do this? For instance, Oracle provides a function called Trunc which does it, but I cannot find an SQL Server equivalent. Anyone? TIA!!!
View 9 Replies
View Related
Dec 3, 2004
Hi all,
I have a table that I've imported into SQL - there is a field in there for date that must have used now(); as its default value (access).
So the values are something like:
01/11/2004 12:16:42
I need a way to change the data so that the time element removed is the field just holds the date. Failing that a way to insert this from the existing field into a new field stripping the date off en route would be a great help.
Many thanks
Phil
View 2 Replies
View Related
Apr 23, 2008
stupid question - how do I strip the time portion from a date returned from now() or
Globals!ExecutionTime.
I MS either used consistent date functions across all platforms or include help in BOL for their VB functions in SSRS.....
View 5 Replies
View Related
Sep 21, 2006
HiI am using SQL 2005, VB 2005I am trying to insert a record using parameters using the following code as per MotLey suggestion and it works finestring insertSQL; insertSQL = "INSERT INTO Issue(ProjectID, TypeofEntryID, PriorityID ,Title, Area) VALUES (@ProjectID, @TypeofEntryID, @PriorityID ,@Title, @Area)"; cmdInsert SqlCommand; cmdInsert=new SqlCommand(insertSQL,conn); cmdInsert.Parameters.Add("@ProjectID",SqlDbType.Varchar).Value=ProjectID.Text; My query is how to detail with dates my previous code wasinsertSQL += "convert(datetime,'" + DateTime.Now.ToString("dd/MM/yy") + "',3), '";I tried the code below but the record doesn't save?string date = DateTime.Now.ToString("dd/MM/yy"); insertSQL = "INSERT INTO WorkFlow(IssueID, TaskID, TaskDone, Date ,StaffID) VALUES (@IDIssue, @IDTask, @TaskDone, convert(DateTime,@Date,3),@IDStaff)"; cmdInsert.Parameters.Add("IDIssue", SqlDbType.Int).Value = IDIssue.ToString();cmdInsert.Parameters.Add("IDTask",SqlDbType.Int).Value = IDTask.Text;cmdInsert.Parameters.Add("TaskDone",SqlDbType.VarChar).Value = TaskDoneTxtbox.Text;cmdInsert.Parameters.Add("Date",SqlDbType.DateTime).Value = date;cmdInsert.Parameters.Add("IDStaff",SqlDbType.Int).Value = IDStaff.Text;Could someone point to me in the right direction?Thanks in advance
View 3 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
Apr 8, 2014
Table:
CREATE TABLE [dbo].[KPI](
[SVP] [varchar](20) NULL,
[Wk1] [int] NULL,
[Wk2] [int] NULL,
[Wk3] [int] NULL,
[Wk4] [int] NULL,
[Wk5] [int] NULL,
[Y] [int] NULL,
[Q] [int] NULL,
[Wk] [int] NULL
)
To generate sample data:
insert into KPI (SVP, Wk1, Wk2, Wk3, Wk4, Wk5, Y, Q, Wk) Values ('SVP', 1,0,0,0,0,2014,1,1)
insert into KPI (SVP, Wk1, Wk2, Wk3, Wk4, Wk5, Y, Q, Wk) Values ('SVP', 0,2,0,0,0,2014,1,2)
insert into KPI (SVP, Wk1, Wk2, Wk3, Wk4, Wk5, Y, Q, Wk) Values ('SVP', 0,0,3,0,0,2014,1,3)
insert into KPI (SVP, Wk1, Wk2, Wk3, Wk4, Wk5, Y, Q, Wk) Values ('SVP', 0,0,0,4,0,2014,1,4)
insert into KPI (SVP, Wk1, Wk2, Wk3, Wk4, Wk5, Y, Q, Wk) Values ('SVP', 0,0,0,0,0,2014,1,5)
[Code] ....
Current result:
SVPWk1Wk2Wk3Wk4Wk5YQWk
SVP10000201411
SVP02000201412
SVP00300201413
SVP00040201414
[Code] ....
Expected result:
SVPWk1Wk2Wk3Wk4Wk5YQ
SVP1234020141
SVP30 1 2 6 9 20142
SVP103226820143
SVP17233141120144
I surely can loop each row and insert the needed value into the result, I want to know if there is a better way to generate the result.
View 2 Replies
View Related
Sep 21, 2015
if I do this:
print @@version
print 'arithmetic with datetime'
go
begin try
declare @datetime datetime = getdate()
[Code] ....
... I get this:
Microsoft SQL Server 2008 R2 (SP2) - 10.50.4042.0 (X64)
Mar 26 2015 21:18:04
Copyright (c) Microsoft Corporation
Express Edition (64-bit) on Windows NT 6.2 <X64> (Build 9200: )
arithmetic with datetime
@datetime = Sep 22 2015 1:39PM
arithmetic with date
Msg 206, Level 16, State 2, Line 3
Operand type clash: date is incompatible with int
Why the inconsistency? Datetime is lenient in this regard - I can even do set @datetime += 0.5 (although the meaning is less intuitive).
View 6 Replies
View Related
Aug 3, 2015
How can I calculate a DateTime column by merging values from a Date column and only the time part of a DateTime column?
View 5 Replies
View Related
Oct 30, 2006
Hi,
I have a date and time variable like dateVariable = '30/10/2006 12:45:36 AM'.(DD/MM/YYYY HH:MM:SS)
From this variable how to fetch only the date part in the format of MM/DD/YYYY
How to write sql query
I mean the result should be like 10/30/2006.
thnx
shaji
View 6 Replies
View Related
Mar 25, 2015
I have four tables: Customer (CustomerId INT, CountyId INT), County (CountyId INT), Search(SearchId INT), and SearchCriteria (SearchCriteriaId INT, SearchId INT, CountyId INT, [others not related to this]).
I want to search Customer based off of the Search record, which could have multiple SearchCriteria records. However, if there aren't any SearchCriteria records with CountyId populated for a given Search, I want it to assume to get all Customer records, regardless of CountyId.
Right now, I'm doing it this way.
DECLARE @SearchId INT = 100
SELECT * FROM Customer WHERE
CountyId IN
(
SELECT CASE WHEN EXISTS(SELECT CountyId FROM SearchCriteria WHERE SearchId = @SearchId)
THEN SearchCriteria.CountyId
[Code] .....
This works; it just seems cludgy. Is there a more elegant way to do this?
View 4 Replies
View Related
Oct 26, 2000
Hi,
Is there any function can give me the date portion only out of Datetime fieldname.
Thanks
View 2 Replies
View Related
Mar 4, 2008
Is there a single function that does that instead of using 3 datepart functions and puting that all together?
View 1 Replies
View Related
Oct 30, 2007
I am trying to count the amount of distinct dates (not datetime) in a table row. The call below returns the amount of distinct datetimes. How do I strip off the time when doing the SQL call?
SELECT COUNT(DISTINCT DT) FROM Event
View 2 Replies
View Related
Mar 11, 2004
Hi
What is the best practice to get the date from a smalldatetime field without the time.
The table contains 5 minute readings for energy consumption in the column period.
Now i need to get all the readings form some dates.
SELECT dbo.TBL_Data.*
FROM dbo.TBL_Data
WHERE (Period IN (CONVERT(DATETIME, '2003-12-31', 102), CONVERT(DATETIME, '2004-01-01', 102)))
this result contains only the readings for the timestamp 00:00
so how to select the whole day ?
kind regards
piet
View 1 Replies
View Related
Sep 2, 2004
Hi,
I have used smalldatetime datatype to store my date and time values. i want to store just the date or time but the problem is it stores both the date and time. For eg, if i add the the date 03/11/2004, it also the stores the current time automatically. so the new value will be something like 03/11/2004 10:00:00 AM where i want just 03/11/2004. further problem is even though i managed to store just the date like 03/11/2004 in the database, whole date and time shows up when i display it in my pages.
any help will be appreciated.
thanx,
View 4 Replies
View Related
Jun 15, 2006
Hi all
How to get just the date portion from a datetime field from sql server?
thanks a lot
View 5 Replies
View Related
Dec 6, 2005
I have a field that contains only a date, and a field that only contains times. If I try to add the two together, I get some meaningless date like year 2111.
The raw data looks like this
EVT_DT='2005-12-05 00:00:00'
EVT_TM='2005-12-06 13:59:00' //today's date
I wrote a function that gives me the minutes past midnight for the EVT_TM
and use a dateadd(n,myMinutesFuntion(EVT_TM),EVT_DT), but it kills the performance in the nexted cursor.
Thanks,
Carl
View 2 Replies
View Related
Jul 23, 2005
Is there any other way which is more simpler(shorter) to get the datepart (I don't want the time part ) of Datetime than this ?Convert(nvarchar, DATEPART(dd,[Date]) ) + '/' + Convert(nvarchar,DATEPART(mm,[Date])) + '/' + Convert(nvarchar, DATEPART(yy,[Date])) As[Date]
View 1 Replies
View Related
Dec 29, 2006
I have a report with a StartDate and EndDate parameter. By default StartDate is the first day of the month (12/1/2006 12:00:00 AM) and EndDate is the last day of the month (01/01/2007 12:00:00 AM). At the bottom of the report, I want it to print StartDate & " through " & EndDate, but I don't want the time on there. My inital thought was to use convert as seen below
=CONVERT(varchar,Parameters!StartDate.Value,101) & " through " & CONVERT(varchar,Parameters!EndDate.Value,101)
When I preview the report I get the following error:
[BC30684] 'CONVERT' is type and cannot be used as an expression.
I really have no idea why I can't use CONVERT in a textbox expression. Does anyone haev any recommendations for getting the following in my footer?
Report Range: 12/01/2006 through 01/01/2007
View 4 Replies
View Related
Sep 3, 2007
OK, I know this is really simple but I can't get my statement to pull just the date from a datetime field!
Here's my query:
select *
from tblPR
where date between convert(datetime, dateadd(day,-day(getdate())+1,getdate()),103)
and convert(datetime, dateadd(day,-day(getdate()),dateadd(month,1,getdate())),103)
I get no errors but I get the timestamp too and I only want the date.
Where am I going wrong?!
Thanks in advance,
Brett
View 3 Replies
View Related
Feb 16, 2008
Hello.
In SQL server 2000 (or 2005) I have a need to query a table for rows with the max date value in a datetime column.
Currently I coded the following to give me a specific date in the column:
...where R.start_time >= '02/15/2008' and R.start_time < DateAdd(day, 1, '02/15/2008')
This gives me the rows with the exact date of 02/15/2008.
So, if I don't want to hard-code the date or pass it as a parameter how can I always get the maximum date back from the query?
Thanks.
Walter
View 6 Replies
View Related
Nov 16, 2006
hai
In my web application i want to bind data from sql 2005 to ultrawebgrid, when i use
source code
dim cmdselect as sqlcommand
dim cmdstring as string
cmdstring="select name, datefieldname from tablename"
cmdselect=new sqlcommand(cmdstring,connectionstring)
connectionstring.open()
ultrawebgrid1.datasource=cmdselect.executenonquery()
ultrawebgrid1.databind()
connectionstring.close()
----- when i execute above coding i am geting date and time displayed there, but i want to display date alone
--my datefield datatype is datetime
- i am using sql 2005,(vs2005-vb/asp.net)
please help me
thanks in advance
View 2 Replies
View Related
Dec 16, 2006
Well yeah as the topic says, this is my sql question right now;string date = "2006-11-12"; string sql = "SELECT * FROM spell_of_work WHERE date='{0}'",date);problem is that my date column in the table is datetime and not a date so.. error! i dont know if RLIKE or LIKE can help, wating for a reply!herman
View 11 Replies
View Related
Jun 2, 2008
here is my select command:
SelectCommand="SELECT [JobID], [EmployeeName],
CAST(
STR(YEAR(DATEENTERED)) + '/' +
STR(MONTH(DATEENTERED)) + '/' +
STR(DAY(DATEENTERED)) AS DATETIME
) AS Date,
[From], [To], [Company], [Catagory], [Client], [Description], [TotalHours] FROM [JcpowersJobs]"
It will show correctly in the query builder test but when you load it up in the gridview it will show the date AND 12:00:00AM for every one of the dates
I tried replacing DATETIME with VARCHAR but it would insert spaces into the date where I didn't want them: EX: (12/04/1994 => 12/ 04/ 1994)
any suggestions?
View 1 Replies
View Related
Dec 13, 2003
Hi All,
I have a SQl Statemnent .... AND dbStartDateTime >= 27/12/2003 19:00:00 .... and get the following error
Incorrect syntax near '19'
I dont understand why it wouldnt like this as this is how it is stored in the database?
I have looked for answers but most people seem to want ot use DateTime without the time
Thanks in advance
Lee
View 2 Replies
View Related
Oct 25, 2004
I have a SQL DB with a column called time_occurred that is formatted like ( 7/28/2004 7:10:30 AM ).
What I need to do is run a report based on just the month day and year portion. I am using the calendar control so mins, sec and milliseconds are not available nor do I really need them.
I am running the Query with this Stored Procedure
ALTER PROCEDURE dbo.Prodecure1
(
@WhereClause varchar(8000)
)
AS
-- Create a variable @SQLStatement
DECLARE @SQLStatement varchar(8000)
-- Enter the dynamic SQL statement into the variable @SQLStatement
SELECT @SQLStatement = 'SELECT column1, column2, etc...' +
@WhereClause
-- Execute the SQL statement
EXEC(@SQLStatement)
RETURN
View 1 Replies
View Related
Jan 4, 2005
Hello respected friends,
can anybody tell me how to write some query in sql for "Microsoft sql" that will get all distinct date parts from the datetime column records that contain also a time part. My question is: "how to get pure and distinct dates from the records in some table that has datetime column containing date and time part"
Thank you very much,
Vuchko
View 1 Replies
View Related
Nov 27, 2011
How I can use only "date" from datetime data type? Because I want only date not time to be display in my application, how to do that ?
View 6 Replies
View Related
Mar 10, 2004
I know there must be a way to do this....
I want to select only the date portion of a datetime field. the date normally shows as similar to '2004-01-01 09:39:52.000'
I need to return just '2004-01-01'. using convert and cast returns the dates as 'JAN 01 2004' - this won't sort correctly, so it is of no use. any suggestions?
thanks,
john
View 3 Replies
View Related
Apr 14, 2008
Hi
I'm having two datetime field in my table. One is Call date and another one is Calltime because of some calculations. So I want to save calldate like 4/14/2008 and calltime like 9:30 PM.
Kindly help me.
View 3 Replies
View Related
Jan 2, 2014
How can I get the hhmmss between 9am to 11am for every date in my datetime column.
I tried:
select datetime from tableA where datetime between '2014-01-03 09:00:00' and '2014-01-31 11:00:00'
But it returns all
datetime
2014-01-31 05:30:00
2014-01-06 09:30:00
2014-01-06 10:30:00
.
.
.
.
View 3 Replies
View Related