473,465 Members | 2,123 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Convert a value to datetime type and format of HH:MM

1 New Member
How to convert a value of 938 declared as a smallint to 09:38 as a datetime type?

To give you the complete set-up that I would like

Expand|Select|Wrap|Line Numbers
  1. SELECT T3.DocNum AS 'Goods Receipt #', T0.DocNum AS 'Sales Order #', T0.DocDate AS 'SO Date', (T1.LineNum +1) As 'Row #', T1.Quantity AS 'Ordered', T1.DelivrdQty AS 'Delivered', T1.OpenQty AS 'Open Qty', T1.ItemCode AS 'Item Code', T1.Dscription AS 'Description' 
  2. FROM ORDR T0  INNER JOIN RDR1 T1 ON T0.DocEntry = T1.DocEntry, PDN1 T2 INNER JOIN OPDN T3 ON T2.DocEntry = T3.DocEntry 
  3. WHERE T1.[LineStatus] = 'O' 
  4. AND  T0.[U_DeliveryCount] > 1 
  5. AND  T1.[ItemCode] =  T2.[ItemCode] 
  6. AND T1.[U_QtePrelever] = 0
  7. AND (
  8. Declare @SAPTime Int    
  9. Declare @SQLTime datetime    
  10. CASE 
  11. WHEN T0.DocTime < '999' THEN  @SAPTime = ((LEFT((T0.DocTime),1)*60) + (RIGHT((T0.DocTime),2))) FROM OPCH T0 where T0.DocEntry = 1
  12. WHEN T0.DocTime > '999' THEN  @SAPTime = ((LEFT((T0.DocTime),2)*60) + (RIGHT((T0.DocTime),2))) FROM OPCH T0 where T0.DocEntry = 1
  13. END
  14. SELECT @SQLTime = CONVERT(CHAR(8),DATEADD(MI,@SAPTime,'20000101'),108)
  15. SELECT DATEDIFF(minute,CONVERT(VARCHAR(5), GETDATE(), 108),@SQLTime)
  16. )<'10'
  17.  
But I get the following errors

Msg 156, Level 15, State 1, Line 8
Incorrect syntax near the keyword 'Declare'.
Msg 156, Level 15, State 1, Line 10
Incorrect syntax near the keyword 'CASE'.
Msg 137, Level 15, State 1, Line 14
Must declare the scalar variable "@SQLTime".
Msg 137, Level 15, State 2, Line 15
Must declare the scalar variable "@SQLTime".


Thx for the help!!
May 4 '10 #1
1 4267
ck9663
2,878 Recognized Expert Specialist
In your sample, is it a straight forward inserting of colon to make it a time value? Or you need to convert to minutes? 938 = 09:38. So there are no 960 value? If yes, then convert to string and insert the colon.

Happy Coding!!!

~~ CK
May 5 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: hikums | last post by:
Does anyone have a function to convert duration in seconds to a format hh:mm:ss Thanks.
1
by: mimi | last post by:
my database has separate field for date and time so we can capture employees' time in and out . In Sql, date can be present in smalldatetime format, which contains only time hh:mm:ss AM/PM. How...
2
by: Robert Brown | last post by:
Hi all. I have written a program that transfers data via FTP. I can calculate the rough amount of time left. I get a value such as 70.83 seconds left for instance. What I want to do is to...
14
by: Michael Barrido | last post by:
I have this for example: Dim iSeconds as int32 = 3600 '3600 seconds is one hour How do i convert it to "01:00:00" ? Please help. Thanks in advance!
1
by: Jason Chan | last post by:
DateTime mydate = new DateTime(2006,1,1,0,0,0); string testStr = mydate.ToString("hh:mm:ss"); //return 12:00:00 mydate = new DateTime(2006,1,1,1,0,0) testStr = mydate.ToString("hh:mm:ss");...
5
nirmalsingh
by: nirmalsingh | last post by:
i am getting date format in string as 30-11-2006 05:59:44 PM . i want to convert in the format of yyyy-mm-dd hh:mm:ss to sore it in mysql database. Help me with sample coding plz..
1
seshu
by: seshu | last post by:
Hi every body to morning my cousine has show his application and also his live db in that to sav the length of all the voice files he has saved in time format ie he took the datatype of time now i...
1
seshu
by: seshu | last post by:
Hi every body to morning my cousine has show his application and also his live db in that to sav the length of all the voice files he has saved in time format ie he took the datatype of time now i...
4
by: Ashraf Ansari | last post by:
Hi, How Can I convert MM/dd/yyyy format into dd/MM/yyyy and the date which is converted into dd/MM/yyyy should be in DateTime format. I do not want to store it as a string. Please help ...
2
by: smitanaik | last post by:
hi i want to do validation of datetime in javascripti.e is i want it in this format dd:mm:yyyy:hh:mm:ss plz heklp me out its urgent
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.