Link to home
Start Free TrialLog in
Avatar of sheana
sheana

asked on

Format Date time with no seconds

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
Avatar of Michel Sakr
Michel Sakr
Flag of Canada image

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..
HI,

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

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

ASKER CERTIFIED SOLUTION
Avatar of indoria
indoria

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of sheana
sheana

ASKER

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.

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
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
Avatar of sheana

ASKER

The above code does not work....PLEASE HELP! I tried it recently and now it does not work. I have made no changes.