473,387 Members | 1,876 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

CONVERSION FROM CHAR(4) TO DATETIME

i have another problem.and it's now on converting a char(4) to datetime
here is the situation
J_TIM < F_TIM

J_TIM is datetime while F_TIM is char of 4

example

J_TIM = 20:30
F_TIM = 2030

how can i convert F_TIM to datetime so that i can compare them.
???

thanks

Nov 23 '06 #1
3 2275
You can try something like:

select *
from sometable
where convert(datetime, '20060101 ' + J_TIM) <
convert(datetime,'20060101 ' + substring(F_TIM,1,2) + ':' +
substring(F_TIM,3,2))

paul_zaoldyeck wrote:
i have another problem.and it's now on converting a char(4) to datetime
here is the situation
J_TIM < F_TIM

J_TIM is datetime while F_TIM is char of 4

example

J_TIM = 20:30
F_TIM = 2030

how can i convert F_TIM to datetime so that i can compare them.
???

thanks
Nov 23 '06 #2
On 22 Nov 2006 22:46:19 -0800, paul_zaoldyeck wrote:
>i have another problem.and it's now on converting a char(4) to datetime
here is the situation
J_TIM < F_TIM

J_TIM is datetime while F_TIM is char of 4

example

J_TIM = 20:30
F_TIM = 2030

how can i convert F_TIM to datetime so that i can compare them.
???

thanks
Hi Paul,

DECLARE @F_TIM char(4);
SET @F_TIM = '2030';
SELECT STUFF(@F_TIM, 3, 0, ':');
SELECT CAST(STUFF(@F_TIM, 3, 0, ':') AS datetime);

Note that the reply posted by othellomy will work, but won't enable you
to efficiently use an index on the J_TIM column (in case there is one).

Also read Tibor's ultimate guide to the datetime datatype. You'll find
it at http://www.karaszi.com/SQLServer/info_datetime.asp

--
Hugo Kornelis, SQL Server MVP
Nov 23 '06 #3
thanks for the codes...they all worked out...
regards!!!
Hugo Kornelis wrote:
On 22 Nov 2006 22:46:19 -0800, paul_zaoldyeck wrote:
i have another problem.and it's now on converting a char(4) to datetime
here is the situation
J_TIM < F_TIM

J_TIM is datetime while F_TIM is char of 4

example

J_TIM = 20:30
F_TIM = 2030

how can i convert F_TIM to datetime so that i can compare them.
???

thanks

Hi Paul,

DECLARE @F_TIM char(4);
SET @F_TIM = '2030';
SELECT STUFF(@F_TIM, 3, 0, ':');
SELECT CAST(STUFF(@F_TIM, 3, 0, ':') AS datetime);

Note that the reply posted by othellomy will work, but won't enable you
to efficiently use an index on the J_TIM column (in case there is one).

Also read Tibor's ultimate guide to the datetime datatype. You'll find
it at http://www.karaszi.com/SQLServer/info_datetime.asp

--
Hugo Kornelis, SQL Server MVP
Nov 24 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Symon R | last post by:
This is a bit of a weird one that I haven't yet been able to solve - I'm hoping someone out there can disprove my findings and tell me where I've gone wrong! I have designed a web service that...
1
by: Amir | last post by:
Hi all, I have a table called PTRANS with few columns (see create script below). I have created a view on top that this table VwTransaction (See below) I can now run this query without a...
3
by: arijitchatterjee123 | last post by:
Hi Group, I am new with SQL Server..I am working with SQL Server 2000. I am storing the date in a nvarchar column of atable.... Now I want to show the data of Weekends..Everything is OK...But the...
1
by: Jama | last post by:
I have dates stored as 20040904(yyyymmdd numeric) in DB2 database. I want to get the difference between two dates. I also have the same database in SQL Server database and I am using the following...
6
by: Mark Rae | last post by:
Hi, Is there any in-built converter which will convert a string like markrae into markrae
0
by: hykyit | last post by:
Hi, I am storing DateTime values in my database in the default mode (mm/dd/yyyy time) and when i retrieve the values from the database, I use:- CONVERT(CHAR(9), ScheduleDate, 3) as ScheduleDate...
2
by: Chris H | last post by:
Hi, I'm trying to concatenate a Description (nchar(100)) and Date (datetime) as Description and my initial effort was just "...description+' '+open_date as description..." which throws a date/...
5
by: Ivan Velev | last post by:
Hello, Minimal example below - it gives me different output if I comment / uncomment the extra time.mktime call - note that this call is not related in any way to main logic flow. When...
1
Manikgisl
by: Manikgisl | last post by:
But the problem is we have dates in Varchar instead Datetime While Converting Varchar To Datetime All four formats are unable to Convert ie select Convert(Datetime,'18-11-2008 2:35:19...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.