Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Formatting time fields

Status
Not open for further replies.

mdr227

Programmer
Nov 17, 2000
114
US
I want to be able to format my time as 7:00 PM in an ASP page. If I don't format it at all it will show up at 7:00:00 PM. If I use a FormatDateTime function with vbShortTime I get it in military time (19:00). Is there a way to format it as 7:00 PM using ASP?
 
Try using the left/right function to cut out the last two zeros:

dim strTime
strTime=rs("MyField")

if len(strTime)=11 then
strTime=left(strTime,4) & " " & right(strTime,2)
else
strTime=left(strTime,5) & " " & right(strTime,2)
end if
 
Thread
RushiShroff (Programmer) Feb 1, 2002
I have a table in access 2000 DB in which there is a field
"Account_Created_Date".I have given datatype "DateTime"

Now I want to insert Time along with Date while account is created.How can I do it with SQL/ASP script?

Regards





Inappropriate post?
If so, Red Flag it!


Check out the FAQ
area for this forum!


Ovatvvon (Programmer) Feb 1, 2002
same things as any other data you are entering into the database. Just assign the server date/time value to a variable to be inserted with the rest of your data...

Dim AccountStart
AccountStart = now()
'will assign the date and time as of Right Now!


Hope this helps!
-Ovatvvon


Click here to mark this post as a helpful or expert post!


Inappropriate post?
If so, Red Flag it!


Check out the FAQ
area for this forum!


RushiShroff (Programmer) Feb 1, 2002
NoW I have inserted DateTime using Now() in the ACCess DB.
How can I seperate them ?
That is while retriving how can I seperate time fraction ?

Regards




Inappropriate post?
If so, Red Flag it!


Check out the FAQ
area for this forum!


Ovatvvon (Programmer) Feb 2, 2002
To format your date input from the database, on your output use the formatDateTime() function. You can pull and display your db value in one of several ways:

------------------------------------------------


formatDateTime(now(),0) = 2/2/2002 1:36:55 AM
This shows just as it is in the db.


formatDateTime(now(),1) = Saturday, February 02, 2002
Long Date


formatDateTime(now(),2) = 2/2/2002
Short Date


-------------------------------------------


formatDateTime(now(),3) = 1:38:41 AM
12 Hour Clock


formatDateTime(now(),4) = 01:35
24 Hour Clock


-------------------------------------------


Additionally, you can pull direct fields from the value using Month(), Day(), Year(). If you were to write,

Response.write Month(now()) & "/" & Day(now()) & "/" & Year(now())

the output would be 2/2/2002

or you can pull time elements like so,

Response.write Hour(now()) & " " & Minute(now()) & " " & Second(now())

Which will produce 1 50 15


You can get more reference to these functions at:




Hope this helps!
-Ovatvvon


Click here to mark this post as a helpful or expert post!


Inappropriate post?
If so, Red Flag it!


Check out the FAQ
area for this forum!


RushiShroff (Programmer) Feb 2, 2002
Thanks,
Ovatvvon
so nice of you...

Regards
Rushi Shroff Rushi@emqube.com
"If freedom is short of weapons,we must compensate with willpower."-Adolf Hitler
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top