Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

ASP.NET Forum


You are currently viewing our ASP.NET Forum as a guest. Please register to participate.
Login



Reply
Displaying first 5 characters from Time Field
Old 08-18-2006, 10:35 AM Displaying first 5 characters from Time Field
Average Talker

Posts: 25
Trades: 0
Hi All,

I have what appears to be a very common problem when displaying a Time field in ASP.
The format will always show HH:MM:SS
However, I would like it to only show HH:MM and having read various pages have decided that the following SQL Select statement is the easiest for me to use:

Code:
"SELECT *,left(Start, 5) AS Start FROM tblform"



The above code works perfectly for me. (The reason for the * is I need to pull all the fields from the table).

However,I have a START and END field in my table and would like to use the same coding for the END field.
I have tried a few variations and cannot seem to get it right!

So, in summary, I'm looking for the correct way to Start and End and only select the first 5 characters from both.
Below is 1 of the examples which is not working:


Code:
"SELECT *,left(Start, 5) AS Start, left(End, 5) AS End FROM tblform"


devine is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 08-18-2006, 10:48 AM Re: Displaying first 5 characters from Time Field
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,519
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
little bit complicated messing around with string slicing in SQL when all you need is a display function

response.write hour(now()) & ":" & minute(now())
or
response.write FormatDateTime(Now(),vbShortTime)

will do exactly the same

BTW your SQL will only work IF the times are stored as strings, when they are stored correctly as datetime fields it will fail.
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 08-18-2006, 12:11 PM Re: Displaying first 5 characters from Time Field
ADAM Web Design's Avatar
Canadastaninianite

Posts: 5,938
Name: Adam for web page design, not program
Location: Toronto, Ontario, Canada
Trades: 0
What chrishirst said.

Also, I can understand you needing to pull all of the fields from your table. Even then, * is not the best way to go about that since it does increase the amount of server resource used quite significantly. You're far better off listing them in your SQL query, no matter how messy it looks.

This code will do what you want:
Code:
Start_Time = FormatDateTime (RS ("Start"), vbShortTime)
Don't put it into your SQL query though.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
(my blog)


Please login or register to view this content. Registration is FREE
(with proof)
ADAM Web Design is offline
Reply With Quote
View Public Profile Visit ADAM Web Design's homepage!
 
Old 08-20-2006, 04:54 AM Re: Displaying first 5 characters from Time Field
Average Talker

Posts: 25
Trades: 0
Hi Guys,
Many thanks for your responses.
I have actually opted to use response.write(left(rs("START"),5)) and response.write(left(rs("END"),5)) instead of messing around with the SQL statement.
But thanks once again for looking into this for me!
devine is offline
Reply With Quote
View Public Profile
 
Old 08-20-2006, 12:24 PM Re: Displaying first 5 characters from Time Field
ADAM Web Design's Avatar
Canadastaninianite

Posts: 5,938
Name: Adam for web page design, not program
Location: Toronto, Ontario, Canada
Trades: 0
No probs.

That's all well and good as long as you want to keep it a string. But it's better to use FormatDateTime in case you ever need to do comparisons (say of Start and End to make sure End > Start or something like that.)
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
(my blog)


Please login or register to view this content. Registration is FREE
(with proof)
ADAM Web Design is offline
Reply With Quote
View Public Profile Visit ADAM Web Design's homepage!
 
Old 08-22-2006, 10:43 AM Re: Displaying first 5 characters from Time Field
Junior Talker

Posts: 4
Name: James
Trades: 0
Session["Time"] = System.DateTime.Now.ToShortTimeString();

The above code will save the short time as a string the session vaiables which means it can be accessed from any page.

Regards j1mb0jay (18)

<misleading link removed>

Last edited by vangogh; 08-23-2006 at 01:59 AM..
j1mb0jay is offline
Reply With Quote
View Public Profile
 
Old 08-24-2006, 07:47 AM Re: Displaying first 5 characters from Time Field
saadatshah's Avatar
Extreme Talker

Posts: 215
Name: Syed Saadat Ali
Location: Lahore, Pakistan
Trades: 0
Its an ASP.NET solution not an ASP one.
__________________
- -- --- ---- ----- ------ ------- ---------------
If you have knowledge, let others light their candles in it.
saadatshah is offline
Reply With Quote
View Public Profile Visit saadatshah's homepage!
 
Reply     « Reply to Displaying first 5 characters from Time Field
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.19018 seconds with 12 queries