Solved

Format Date time with no seconds

Posted on 2001-07-16
7
1,562 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:Silvers5
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 50 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

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…
Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

761 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