Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Change time format
Message
 
À
10/03/2003 11:12:11
Information générale
Forum:
Visual FoxPro
Catégorie:
Gestionnaire de rapports & Rapports
Divers
Thread ID:
00763687
Message ID:
00764199
Vues:
33
Hello Sapna,

>How do I change the time on the report header so that it would show up in a 12-hour format instead of a 24-hour format

You have to manipulate the string that is returned by the TIME() function to make it suitable for civilians. Here's a UDF that's been in my Fox bag-o-tricks for quite a while now:
FUNCTION str_time   && (STRing_of-TIME)
*-----------------------------------------------------------------------
*-- Original Author: Guillermo Guerra   FOXUDF.PRG
*-- Placed in the Public Domain on 07/01/95
*-- (Got this one off somebody's home page on the InterNet)
*-- Programmer..: Randy Bosma      *-- Date........: 27.Mar.1996
*-- Notes.......: Returns a string something like "12:51p" or "3:18a"
*-- Written for.: FoxPro 2.5
*-- Called by...: Any
*-- Usage.......: str_time()
*-- Parameters..: None
*-- Calls.......: None             
*-- Returns.....: a formatted string of the current time
*-- Example.....: STORE DTOC(DATE())+ "  "+ str_time()  TO wp
*-- Revised:   By:   Changes:
*-- 28.Mar.96  RBB - Changed to work in dB5
*-----------------------------------------------------------------------
** store time in 12 hour format to a chr string
STORE SUBSTR(TIME(),1,2) TO hr
**************** between 00 hrs and 9 hrs (12a-9a)
IF VAL(hr) >= 0 .AND. VAL(hr) < 10
   STORE "a" TO tod
   IF hr = "00"
      STORE "12" TO hr12
   ELSE
      STORE SUBSTR(hr,2,1) TO hr12
   ENDIF && hr = "00"
ENDIF && VAL(hr) >= 0 .AND. VAL(hr) < 10
**************** between 10 hrs and 12 hrs (10a-11a)
IF VAL(hr) > 9 .AND. VAL(hr) < 12
   STORE "a" TO tod
   STORE hr TO hr12
ENDIF && VAL(hr) > 9 .AND. VAL(hr) < 12
**************** 12pm+
IF VAL(hr) = 12
   STORE "p" TO tod
   STORE LTRIM(STR(VAL(hr))) TO hr12
ENDIF && VAL(hr) >= 12
**************** 12pm to 11pm
IF VAL(hr) > 12
   STORE "p" TO tod
   STORE LTRIM((STR(VAL(hr)-12))) TO hr12
ENDIF && VAL(hr) >= 12
STORE SUBSTR(TIME(),4,2) TO MIN
STORE LTRIM(hr12+":"+LTRIM(MIN)+tod) TO stime
RETURN stime
*
*	EOFunc str_time
*--
Well, it looks like this I could use some updating and improvements.
HTH,
Randy Bosma
VFP - Because life is too short to code in something else...
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform