Date/Time Info And Script Links
Apr 15, 2006
This post is to provide information and Script Library links related to datetime. There are also links to other resources.
List of Subjects
Typical Date Query
Uses of the DATETIME data type
Finding the Start of Time Periods
Finding the End of Time Periods
Generating Date Tables
Getting Time Only from DateTime
Finding Age
Finding ISO Weeks
Converting Year, Month, and Day to DateTime
Converting to/from UNIX Time
Finding the midpoint between two datetimes
Generating Random Datetimes
Creating a Formatted Calendar
Links to other Date, Time, and Calendar Resources
Typical Date Query
How to query a table with a selection on a datetime column, for example, find all items for the date 2006-01-14. This isn’t really a script, but it is one of the most common questions about datetime.
Select
*
from
NyTable
Where
MyDateColumn >= '20060114' and
MyDateColumn < '20060115'
Notice that you are asking for greater than or equal to the beginning of the date, and less than the following date. You can apply the same general query for any range of days. This is almost always the best way to write a query of this type, because it allows SQL Server to use any index that exists on the datetime column, and it uses less resources than a query that applies a function to the datetime column.
Notice that the query dates are in format YYYYMMDD; you should always use this format for date strings. This is SQL Servers "universal" date format that works the same with all settings of DATEFIRST. Any other format may produce an error if the setting of DATEFIRST is not exactly what you expect.
For datetime strings use universal format
YYYYMMDD HH:MM:SS.MIL (20061231 23:59:59.997).
Uses of the DATETIME data type
The DATETIME data type can be used to hold four different types of date/time values:
1. Date and time – a date and time together
Example: 2006-07-15 12:06:15.333
2. Date – a date only stored as the time at midnight:
Example: 2006-07-15 00:00:00.000
3. Time – a time only stored as time on the DATETIME zero date, 1900-01-01.
Example: 1900-01-01 12:06:15.333
4. Elapsed time – a difference between two DATETIME values, stored as the time since the DATETIME zero point, 1900-01-01 00:00:00.000.
Example: 1900-01-03 14:12:34.443
The actual usage of the value is only defined in the context of the application. There is no way to specify that a DATETIME is to be used for a date and time, date only, time only, or elapsed time. It is possible to insure that a column in a table contains date only or time only by adding a constraint to a column, but is is necessary that the application format the DATETIME value properly.
The following script briefly demonstrates the four different ways to use DATETIME, and several conversions from one type to another: date and time to date only, date and time to time only, date only plus time only to date and time, two date and time values to elapsed time, and elapsed time to individual days, hours, minutes, seconds, and milliseconds.
-- Demo four uses of DATETIME datatype
declare @datetime1 datetime
declare @datetime2 datetime
declare @date_only datetime
declare @time_only datetime
declare @date_plus_time datetime
declare @elapsed_time datetime
declare @elapsed_days int
declare @elapsed_hours int
declare @elapsed_minutes int
declare @elapsed_seconds int
declare @elapsed_milliseconds int
-- Load 2 datetime values
select @datetime1 = '20060715 12:06:15.333'
select @datetime2 = '20060718 02:18:49.777'
-- Get date only from datetime using DATEAADD/DATEDIFF functions
select @date_only = dateadd(day,datediff(day,0,@datetime1),0)
-- Get time only from datetime by subtracting date only
select @time_only = @datetime2-dateadd(day,datediff(day,0,@datetime2),0)
-- Add date only and time only together
select @date_plus_time = @date_only+@time_only
-- Get elapsed time as the difference between 2 datetimes
select @elapsed_time = @datetime2-@datetime1
-- Get elapsed time parts as time since 1900-01-01 00:00:00.000
select @elapsed_days = datediff(day,0,@elapsed_time)
select @elapsed_hours = datepart(hour,@elapsed_time)
select @elapsed_minutes = datepart(minute,@elapsed_time)
select @elapsed_seconds = datepart(second,@elapsed_time)
select @elapsed_milliseconds = datepart(millisecond,@elapsed_time)
declare @cr varchar(4), @cr2 varchar(4)
select @cr = char(13)+Char(10)
select @cr2 = @cr+@cr
print'Results:'+@cr2
print'Datetime1 = '+convert(varchar(30),@datetime1,121)+@cr+
'Datetime2 = '+convert(varchar(30),@datetime2,121)+@cr2
print'Date Only = '+convert(varchar(30),@date_only,121)+
', from Datetime1 = '+convert(varchar(30),@datetime1,121)+@cr2
print'Time Only = '+convert(varchar(30),@time_only,121)+
', from Datetime2 = '+convert(varchar(30),@datetime2,121)+@cr2
print'Add date and time: '+convert(varchar(30),@date_plus_time,121)+' ='+@cr+
' '+convert(varchar(30),@date_only,121)+
' + '+convert(varchar(30),@time_only,121)+@cr2
print'Elapsed Time: '+convert(varchar(30),@elapsed_time,121)+' ='+@cr+
' '+convert(varchar(30),@datetime2,121)+
' - '+convert(varchar(30),@datetime1,121)+@cr2
print'Elapsed Time Parts:'+@cr+
' Days = '+convert(varchar(20),@elapsed_days)+@cr+
' Hours = '+convert(varchar(20),@elapsed_hours)+@cr+
' Minutess = '+convert(varchar(20),@elapsed_minutes)+@cr+
' Secondss = '+convert(varchar(20),@elapsed_seconds)+@cr+
' Milliseconds = '+convert(varchar(20), @elapsed_milliseconds)+@cr2+@cr2Results:
Datetime1 = 2006-07-15 12:06:15.333
Datetime2 = 2006-07-18 02:18:49.777
Date Only = 2006-07-15 00:00:00.000, from Datetime1 = 2006-07-15 12:06:15.333
Time Only = 1900-01-01 02:18:49.777, from Datetime2 = 2006-07-18 02:18:49.777
Add date and time: 2006-07-15 02:18:49.777 =
2006-07-15 00:00:00.000 + 1900-01-01 02:18:49.777
Elapsed Time: 1900-01-03 14:12:34.443 =
2006-07-18 02:18:49.777 - 2006-07-15 12:06:15.333
Elapsed Time Parts:
Days = 2
Hours = 14
Minutess = 12
Secondss = 34
Milliseconds = 443
Finding the Start of Time Periods
One of the most common questions is how to remove the time from a datetime so that you end up with just a date. In other words, change 2006/12/13 02:33:48.347 to 2006/12/13 00:00:00.000. The following links have functions that will find the start of Century, Decade, Year, Quarter, Month, Week, Day, Hour, 30 Minutes, 20 Minutes, 15 Minutes, 10 Minutes , 5 Minutes , x number of Minutes ,Minute , or Second.
Start of Time Period Functions:
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=64755
Start of Week Function:
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=47307
Start of Week Function, Part Deux:
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=59927
Convert DateTime to Date using Rounding UDF:
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=62354
Finding the End of Time Periods
Sometimes there is a need to find the last day of a time period. The following links have functions that will find the last day of Century, Decade, Year, Quarter, Month, or Week.
End Date of Time Period Functions:
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=64759
End of Week Function:
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=64760
Generating Date Tables
It can be very useful to have a table with a list of dates, and various attributes of those dates, especially for complex reporting. The functions on these links can be used to load a date table with many different columns of date attributes.
Date Table Function F_TABLE_DATE:
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=61519
Here is another approach that also includes a function for calculating Easter. I haven’t tried it myself.
Create Date Table with UK & Easter bank holidays:
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=49711
Getting Time Only from DateTime
By convention, a time only column is stored in SQL Server as an offset from 1900-01-01 00:00:00.000. The function on this link will get the time from a datetime value.
Time Only Function: F_TIME_FROM_DATETIME
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=65358
Finding Age
Computing the age of someone is more difficult than it might seem when you take into account different month lengths, leap year, and other things.
This function returns age in format YYYY MM DD.
Age Function F_AGE_YYYY_MM_DD:
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=62729
This function returns age in years.
Age Function F_AGE_IN_YEARS:
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=74462
This link is more of a discussion of the problem of calculating age than a script you can use, but it does show the difficulties. I haven’t tried it myself.
Calculating age in years:
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=11578
Finding ISO Weeks
The ISO 8601 standard for dates defines a standard way of assigning a unique number to each week starting on Monday. The following functions can be used to return ISO weeks. The date table functions mentioned in the "Generating Date Tables" subject above also have columns for ISO weeks.
ISO Year Week Day of Week Function:
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=60515
ISO Week of Year Function:
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=60510
Converting Year, Month, and Day to DateTime
The functions on this link will take input parameters of Year, Month, and Day and return a datetime. There are several version posted.
Make Date function (like in VB):
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=22339
Converting to/from UNIX Time
The functions in this script can be used to convert to/from SQL Server date time to UNIX Time.
UNIX Time Conversion Functions:
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=66858
Finding the midpoint between two datetimes
The function in this script finds the midpoint in time between two datetimes.
Datetime Range Midpoint Function
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=68806
Generating Random Datetimes
The functions on this link can be used to generate random datetimes, random integers, and random samples.
Random Integer, Sample, and Datetime Functions
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=69499
Creating a Formatted Calendar
There are several methods is this link that will return a result set with a formatted calendar.
Calender In Sql Server:
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=44865
Links to other Date, Time, and Calendar Resources
This post has links to other resources for date and time information, as well as many other commonly asked questions about SQL Server.
FAQ - Frequently Given Answers:
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=55210
This blog entry has links to various date time subjects.
Fun with Dates (Date Conversion examples):
http://weblogs.sqlteam.com/brettk/archive/2005/06/02/5528.aspx
This external link has a lot of information on the SQL Server datetime datatype, writing queries with datetime, and various datetime operations.
Demystifying the SQL Server DATETIME Datatype:
http://www.sql-server-performance.com/fk_datetime.asp
These external links are a series of articles about working about working with SQL Server Date/Time.
Working with SQL Server Date/Time Variables:
http://www.databasejournal.com/features/mssql/article.php/10894_2191631_1
Part Two - Displaying Dates and Times in Different Formats:
http://www.databasejournal.com/features/mssql/article.php/10894_2197931_1
Part Three - Searching for Particular Date Values and Ranges:
http://www.databasejournal.com/features/mssql/article.php/10894_2209321_1
Part Four - Date Math and Universal Time:
http://www.databasejournal.com/features/mssql/article.php/10894_2216011_1
This external link explains how the datetime datatypes work in SQL Server, including common pitfalls and general recommendations.
Guide to the datetime datatypes:
http://www.karaszi.com/SQLServer/info_datetime.asp
These external links discuss the ISO 8601 standards of dates and times.
Numeric representation of Dates and Time:
http://www.iso.org/iso/en/prods-services/popstds/datesandtime.html
ISO 8601:
http://en.wikipedia.org/wiki/ISO_8601
A summary of the international standard date and time notation:
http://www.cl.cam.ac.uk/~mgk25/iso-time.html
This external link explains how time is calculated on UNIX systems.
Unix Time:
http://en.wikipedia.org/wiki/Unix_time
These are external links to the U.S. Naval Observatory, an authority in the area of Precise Time.
The U.S. Naval Observatory Home:
http://www.usno.navy.mil/
The Official Standard of Time for the United States:
http://tycho.usno.navy.mil/
This external link has Clock, Calendar, Time Zone, and Holiday information for most of the world:
http://www.timeanddate.com/
This external link has a lot of information on the subject of Calendars.
Frequently Asked Questions about Calendars:
http://www.tondering.dk/claus/calendar.html
If you don't have any idea what all this is about,
You may need to Learn SQL:
http://www.sql-tutorial.net/
http://www.firstsql.com/tutor.htm
http://www.w3schools.com/sql/default.asp
And finally, the primary Microsoft SQL Server References:
SQL Server 2000 Books Online
http://msdn2.microsoft.com/en-us/library/aa257103(SQL.80).aspx
SQL Server 2005 Books Online
http://msdn2.microsoft.com/en-us/library/ms130214.aspx
CODO ERGO SUM
View 20 Replies
ADVERTISEMENT
Aug 16, 2006
I am attempting to write a SQL query that retrieves info processed between two times (ie. 2:00 pm to 6:00 pm) during a date range (ie. 8/1/06 to 8/14/06)... I am new to SQL and am perplexed... I have referenced several texts, but have not found a solution. Even being pointed in the right direction would be greatly appreciated!!
View 6 Replies
View Related
Jun 30, 2007
This is driving me nuts..
I'm trying to extract some data from a table in oracle. The oracle table stores date and time seperately in 2 different columns. I need to merge these two columns and import to sql server database.
I'm struggling with this for a quite a while and I'm not able to get it working.
I tried the oracle query something like this,
SELECT
(TO_CHAR(ASOFDATE,'YYYYMMDD')||' '||TO_CHAR(ASOFTIME,'HH24:MM : SS')||':000') AS ASOFDATE
FROM TBLA
this gives me an output of 20070511 23:06:30:000
the space in MM : SS is intentional here, since without that space it appread as smiley
I'm trying to map this to datetime field in sql server 2005. It keeps failing with this error
The value could not be converted because of a potential loss of data
I'm struck with error for hours now. Any pointers would be helpful.
Thanks
View 3 Replies
View Related
Aug 5, 2015
I'm looking for a way of taking a query which returns a set of date time fields (probable maximum of 20 rows) and looping through each value to see if it exists in a separate table.
E.g.
Query 1
Select ID, Person, ProposedEvent, DayField, TimeField
from MyOptions
where person = 'me'
Table
Select Person, ExistingEvent, DayField, TimeField
from MyTimetable
where person ='me'
Loop through Query 1 and if it finds ANY matching Dayfield AND Timefield in Query/Table 2, return the ProposedEvent (just as a message, the loop could stop there), if no match a message saying all is fine can proceed to process form blah blah.
I'm essentially wanting somebody to select a bunch of events in a form, query 1 then finds all the days and times those events happen and check that none of them exist in the MyTimetable table.
View 5 Replies
View Related
Jul 31, 2002
How do I get the file name appended with the time stamp info like this:
Order_file__2002626_8_34_4.csv in an automated process which generates the file? Any help??
Thanks.
Reddy.
View 1 Replies
View Related
Oct 22, 2015
I am trying to load previous days data at 3 am via a SSIS job.
The Date variable is initiated as DATEADD("dd",-1, GETDATE()) in the for loop.
Now, as this job runs at 3 am, and I set the variable as GETDATE() - 1, it excluded the data from 12 am to 3 am in the resultset as Date is set as YYYY-MM-DD 03:00:00:000 I need this to be set as YYYY-MM-DD 00:00:00:000
How can i do this?
View 2 Replies
View Related
Jun 13, 2002
In SQL Server 2000:
How do I convert a Julian date to a Gregorian date?
How do I convert a Gregorian date to Julian?
Examples please.
Many thanks in advance.
Gary Andrews
View 2 Replies
View Related
Mar 18, 2014
I have the following
Column Name : [Converted Date]
Data Type : varchar(50)
When I try and do month around the [Converted Date] I get the following error message
“Msg 241, Level 16, State 1, Line 2
Conversion failed when converting date and/or time from character string.”
My Query is
SELECT
month([Created Date])
FROM [FDMS_PartnerReporting].[Staging].[Salesforce_MarketingReporting]
View 7 Replies
View Related
Nov 16, 2015
SELECT * ,[Due]
FROM [Events]
Where Due >= getdate() +90
This returns the error: Conversion failed when converting date and/or time from character string
Why would this be? How to cast or convert this so that it will work?
View 24 Replies
View Related
Nov 13, 2007
Hi there.
I'm trying to extract data from my SQL server & everything in the script I've got is working (extracting correct data) except for one field - which is for the most part it's off by +2 days (on a few occasions - I see it off by just +1 day or even +3, but it's usually the +2 days).
I'm told that it's due to the conversion formula - but - since SQL is not my native language, I'm at a bit of a loss.
The DB table has the date field stored as a type: CHAR (as opposed to 'DATE')
Can anyone out there help?
Please advise. Thanks.
Best.
K7
View 1 Replies
View Related
Sep 5, 2007
Dear Expert!
A server with SQL 2005 sp2, Reporting Services and Sharepoint services (ver 3.0) (in integrated mode) gives an odd error. When viewing a Reporting Services report with a Date Time Picker, the date chosen is wrong. The preferred setting is Danish with the date format dd-mm-yyyy. The date picker shows the months in Danish but when selecting a date, and clicking on the Apply-button, the date reformats to US (mm-dd-yyyy).
Example:
When choosing 5th of September 2007 and clicking apply, it shows in the picker, 9th of May 2007.
When choosing 26th of September 2007 and clicking apply, it shows, again in US format, the RIGHT date but adds a timestamp 12:00 AM? in the end, making further enquiries to fail.
The report itself receives the right date and shows correctly. The only case it fails is, when the time stamp appears.
The server is a 32-bit one with 4 GB RAM. A testserver with identical collation on the Reportserver database cannot recreate the error. The site containing the reports has been set to Danish in the regional settings. To Reinstall is not an option.
The test report has no database connection whatsoever.
When setting the site to US, the timestamp wont appear at all.
The server has been restarted and the installation procedure was of the simple kind. No special tweaks at all.
Any advice would be greatly appreciated.
Kind Regards
Johan Rastenberger
View 1 Replies
View Related
Jan 15, 2002
Hello,
we need to track date/time of last update for each record in a table.
As we understand it, we can't use field type Timestamp as this type does
not use dates/times.
Is there any SQL function available which we can bind to a column or
do we really have to use triggers?
Greetings from Mannheim, Germany
Ricardo
View 2 Replies
View Related
Jan 15, 2002
Hello,
we need to track date/time of last update for each record in a table.
As we understand it, we can't use field type Timestamp as this type does
not use dates/times.
Is there any SQL function available which we can bind to a column or
do we really have to use triggers?
Greetings from Mannheim, Germany
Ricardo
View 1 Replies
View Related
Nov 11, 2013
I want to update the time in a datetime field with the current time.
Fields current value is:
2013-11-11 00:00:00.000
I want to insert this into another table and when I do I want to grab the current time and update that field.
field name: picked_dt
Table: oeordlin
or is there a way through sql to update the time when the picked_dt is updated?
View 2 Replies
View Related
Jun 12, 2007
Hi
i have the following situation. in my database i have a datetime field (dd/mm/yy hh:mms) and i also have a field timezone.
the timezone field has values in minutes that i should add to my datetime field so i have the actual time.
afterwards i split the datetime into date and time.
the last part i can accomplish (CONVERT (varchar, datetime, 103) as DATEVALUE and CONVERT (varchar, DATETIME, 108) as TIMEVALUE).
could anybody tell me how i can add the timezone value (in minutes) to my datetime value ?
i do all the calculations in my datasource (sql).
Thanks
V.
View 3 Replies
View Related
Mar 16, 2014
I want to display only the date part of a date field which contains both date & time information.
For example I have the value '2013-11-14 00:00:00.000' in my result set, and ideally I would like to show only '2013-11-14'.
I have looked up the datepart() command, however I can't work out how to return all parts of the date, rather than just the year, month, or day.
View 3 Replies
View Related
Jul 4, 2014
I have passed createdDate from UI to Stored procedure.createdDate field declared with DateTime.it is having value 2014-07-01.I need to fetch records from the database based upon the created field.but Create_TM in database having value Date with timestamp.so how would i change the createdfield in stored procedure.
ALTER PROCEDURE [dbo].[ByDateRange]
@Feed VARCHAR(50),
@CreatedDate DATETIME
select * from Date_table where Create_TM = @CreatedDate
View 1 Replies
View Related
Dec 29, 2005
I have a table named "shift" and I need to setup my query to return only data where the field "startime" = today. The problem I am running into is the starttime field it laid out like "2005-12-29 14:00:00" with different time values. I need to ruturn everything that has todays date regardless of the time value. I tried using GetDate() but that is returning data for other days as well or just data before or after the current time. Does anyone have any suggestions? This is driving me crazy! Thanks, Garrett
View 7 Replies
View Related
Oct 4, 2007
Hello,
We have a bunch of Audit tables that contain almost exact copies of the operations tables. The audit tables also include:
AuditID - the audit action (insert, modify - old, modify - new, deleted)
AuditDate - date and time of action
AuditUser - User who did it...
At the end of the day I need to know for any given record what it looked like at the beginning of the day and what it looks like at the end of the day. There could have been numerous changes to the record throughout the day, those records I am not interested in. Only the first record and the last record of a give day.
I am going to be doing a lot of MIN(AuditDate) and MAX(AuditDATE) and .. WHERE AuditDate BETWEEN '10/1/2007 00:00:00' AND '10/1/2007 11:59:59' ...
Question: Whats better for performance:
1. Separating out the date and time and doing a clusterd index on the date.
2. Keeping date and time in the same column and just use a normal index.
3. Better ideas?
Thanks,
Bradley
View 1 Replies
View Related
May 2, 2008
Hi,I need a way of changing the following SQL statement so that the dates are without the hh:mm:ss tt:"Select DISTINCT([StartDate]) From [Events]"How can this be done?Thanks,Curt.
View 4 Replies
View Related
Jan 8, 2013
I have a table in which a date value is stored as varchar.some of these values are stored ina dd/mm/yyyy format and other values are stored in a yyyy-mm-dd format..Now I wish to retrieve some data by querying between two dates. However I need to convert the varchar date value to datetime in order to do this but since the date value is in two different formats, the following doesn't work.
select date_value
from my_table
where CONVERT(DATETIME, date_value, 103) between @date1 and @date2
How can you convert the date value to datetime when its stored in mutiple formats. I can't change the table itself as I dont have admin privelages.
View 14 Replies
View Related
Jan 24, 2008
Hello,
I am using the calender parameter and I need to convert my data date format to the one that matched that is returned on selecting a date from this calender. Can you show me what this format is.
how can I convert my existing date format to this format. The existing date format is 2007-07-26 21:27:13.000
thank you
Kiran
View 5 Replies
View Related
May 16, 2008
How can I obtain just the time portion from a date/time column?
My data contains "2008-05-19 09:30:00.000"
Actually, all I want/need is the hh:mm part of it.
Thanks,
Walt
View 2 Replies
View Related
May 7, 2007
I want to be able to see when records have been added to a table. The issue is we have a DTS job scheduled to run every night. The developer who wrote it password protected it and doesn't work here anymore. I want to add a step to this series of DTS jobs and want to run it just prior to his job. Is there a way to see when the records are being added or when this job is being run? Thanks again, you guys are the best.
ddave
View 3 Replies
View Related
May 5, 2004
SELECT ltrim(str(datepart(yyyy,getdate()))) +'-'+
replicate('0',2-len(ltrim(str(datepart(mm,getdate())))))+ltrim(str (datepart(mm,getdate())))+'-' +replicate('0',2-len(ltrim(str(datepart(dd,getdate())))))
+ltrim(str(datepart(dd,getdate())))
This is how i am getting datepart of datetime.Is there any other way to get the date and also time seperately..
Thanks.
View 14 Replies
View Related
Feb 28, 2008
i have a query
select mydate,lastname from users
group by mydate,lastname
now the only thing is mydate is a datetime fields but i want the results to group by just the date for each lastname entered.
How do i do this?
View 3 Replies
View Related
Jul 20, 2005
I have a table that's of type date/time (i.e. 01/01/1900 00:00:00).What I want is to do the following:Say you have these records:person | date-time-------+---------------------------jim | 06/02/2004 00:05:52jim | 06/02/2004 05:06:21jim | 06/02/2004 05:46:21jim | 06/15/2004 11:26:21jim | 06/15/2004 11:35:21dave | 06/04/2004 09:35:21dave | 06/04/2004 11:05:21dave | 06/06/2004 10:34:21dave | 06/08/2004 11:37:21I'd like the results to count how many days and returnperson | days-------+-------jim | 2dave | 3How would I do this?--[ Sugapablo ][ http://www.sugapablo.com <--music ][ http://www.sugapablo.net <--personal ][ Join Bytes! <--jabber IM ]
View 1 Replies
View Related
Jan 24, 2008
I have an SSIS package that moves data from SQL Server to an legacy Access database. In SQL Server, there is a date/time column that I need to split into a separate date column and time column in the access database. Initially I just created a derrived column for the time and set the expression equal to the source date/time column from SQL Server. Unfortunately, that just makes the date column and time column the same having the full date/time.
What expression can I use during a derrived column transformation to assign just the date to a derrived column and just the time to another derrived column?
Thanks,
Steve
View 3 Replies
View Related
Jul 13, 2006
I would like to know how to do a select on a datetime field that will return to me only the Date but not the time. Please help out. Thanks.
I ran through all the built in date functions and couldn't find anything for this task. I still can't fathom why there isn't a date function for this simple but a must have option.
blumonde
View 10 Replies
View Related
Apr 3, 2008
Hi
I have created a simple SQL database with four columns using Microsoft SQL Server Mangement Studio Express - (Name(varchar), Email (varchar), Comment (varchar), Datetime). The idea is for this database to hold feedback and comments from my website by connecting a form view with insert capabilities to this database. How can I configure the Datetime column in the database to automaticaly input the time and date from when the user posted the comment?
Thanks
View 3 Replies
View Related
Feb 19, 2004
I am setting up an SQL database and I will need to get differences in dates. For example I have a start date, start time, completion date and completion time and I want to get the difference between the start and completion.
Would it be better to have one field with both date and time in it, or better to have a date field and a time field?
Even though I have already started setting up the tables with seperate fields for date and time I am now leaning toward one field with date/time in it. (Only because that is the way I had to do it when setting up an Excel spreadsheet for a similar task)
When that is decided could someone please point me to a good resource for explaining to me the iConvertible method. I tried a simple asp.net page to insert a record into the database and got an error method telling me I had to use the iConvertible method. (I am programming in C#). I use a textbox on a webform to input the date and time information and the SQL database fields are set up as date/time. I looked at the visual studio documentation but that doesn't help me much. It doesn't show me the syntax required and how to "use" the method.
Thanks
View 2 Replies
View Related
Mar 13, 2001
Does anyone know how to determine the next run date and time of a scheduled job while the job is running? I have found that using DMO or SPs to find this information while a job is running returns the time the job started. I am not sure but I believe that SQL Server calculates the next run time after the job has been completed if anyone knows to figure this out while a job is running I would greatly appreciate it. Thanks
Keith
View 1 Replies
View Related
Nov 15, 2005
I have a two fields one called Date and another called time. I would liked to combine these fields and then create another field that would just reflect the time. Here is and ex.
Field-DATE - 8/20/1967 Field - TIME-11:50
I would like to do this:
Field-DATE-11/20/1967 115025 Field-TIME - 11:50
Can someone tell me how can I do this. Again I just want to combine the date and time field then create a field that will only reflect the time. But the time must be the same as what was combined. If you need further clarification feel free to just ask.
View 1 Replies
View Related