Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Format Date time with no seconds

Posted on 2001-07-16
7
Medium Priority
?
1,568 Views
Last Modified: 2009-03-02
Hi! When I FORMATDATETIME and specify 2 for e.g. FORMDATETIME(NOW(),2)...it gives me the time with seconds. How can I get rid of the seconds...I would like it to display

2:30 PM

instead of

2:30:00 PM

Please help
0
Comment
Question by:sheana
7 Comments
 
LVL 20

Expert Comment

by:Michel Sakr
ID: 6288611
change the regional settings to not display seconds.. or try:

MyVar = Left(MyVar,len(MyVar)-6) & Right(MyVar,3)

Cdate it next if needed to be a date data type.. otherwise leave MyVar as is..
0
 
LVL 4

Expert Comment

by:ravi_raj123
ID: 6288632
HI,

Try using formatdatetime(Now(),4), this will give you the time in HH:MM format. 4=vbShortTime

Hope this helps you.
GOOD LUCK...:)

0
 

Accepted Solution

by:
indoria earned 150 total points
ID: 6288635
hi try this.....

<%
strAMPM = instr(1,FormatDateTime(now(),3),"AM")

if strAMPM > 0 then
 Response.Write FormatDateTime(now(),4)& " AM"
else
 strtime = mid(FormatDateTime(now(),3),1,5)
 Response.Write strtime & " PM"
end if
%>

indoria
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

Author Comment

by:sheana
ID: 6288686
Thanks.

<%
strAMPM = instr(1,FormatDateTime(now(),3),"AM")

if strAMPM > 0 then
Response.Write FormatDateTime(now(),4)& " AM"
else
strtime = mid(FormatDateTime(now(),4),1,5)
Response.Write strtime & " PM"
end if
%>
This code worked perfectly.

Thanks Indoria.

0
 

Expert Comment

by:indoria
ID: 6288722
hi again .. herez little modification in previous code..

<%
strAMPM = instr(1,FormatDateTime(now(),3),"AM")
if strAMPM > 0 then
 Response.Write FormatDateTime(now(),4)& " AM"
else
  strtime = mid(FormatDateTime(now(),3),1,5)
  if mid(strtime,len(strtime),1) = ":" then
    Response.Write  mid(strtime,1,len(strtime)-1) & " PM"
  else
    Response.Write strtime & " PM"
  end if
end if
%>

This is tested on Win envi.
indoria
0
 

Expert Comment

by:indoria
ID: 6288728
hi again .. herez little modification in previous code..

<%
strAMPM = instr(1,FormatDateTime(now(),3),"AM")
if strAMPM > 0 then
 Response.Write FormatDateTime(now(),4)& " AM"
else
  strtime = mid(FormatDateTime(now(),3),1,5)
  if mid(strtime,len(strtime),1) = ":" then
    Response.Write  mid(strtime,1,len(strtime)-1) & " PM"
  else
    Response.Write strtime & " PM"
  end if
end if
%>

This is tested on Win envi.
indoria
0
 

Author Comment

by:sheana
ID: 7024026
The above code does not work....PLEASE HELP! I tried it recently and now it does not work. I have made no changes.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Suggested Courses

972 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question