Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Outputting Time

New Here ,
Oct 03, 2008 Oct 03, 2008
Hi all,

I've started using dates/times on my websites stored in a date/time field in my database. In the past, when I typed in times on my site rather than pulled them from a database, I formatted them slightly different than CF does. For example, if the time was 9 in the morning, I would key in 9 a.m. on my site. However, because of the date/time field in Access, the time gets output as 9:00 AM. Two questions: 1) Is there a way to drop the two zeros and 2) Can I make AM/PM show up as a.m./p.m.

I know it seems extremely picky, but I want this great transition to dynamic dates to be seemless for my users.

Thanks!
533
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 03, 2008 Oct 03, 2008
Presuming that you are now using proper date/time objects like you
should be from your database. Then you just need to look at the
timeFormat() function which can do all you want and more.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 03, 2008 Oct 03, 2008
Don't worry about how it looks in Access. That's got nothing to do with how it will look on your site.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 03, 2008 Oct 03, 2008
Maybe I'm missing something. Right now, with the formatting I'm using, the time looks the same as it does in the database.

Here is the format I have in place right now: #TimeFormat(StartTime, "h:mm tt")# If the time is 9 in the morning, CF outputs it as 9:00 AM. I'd like it to show up as 9 a.m. If the time is 9:30 in the morning, CF outputs 9:30 AM. I'd like it to show up as 9:30 a.m. Does that explain things a little clearer?

Thanks!
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 03, 2008 Oct 03, 2008
straffenp wrote:
> Does that explain things a little clearer?

Yes, but you are looking at conditional formatting which you are not
going to get with one function. First of all your AM to a.m. is a
straight forward string replace.

replace(timeFormat(startTime,"h:mm tt"),"AM","a.m.")

But the minute issue is not quite so straight forward. This is
conditional formatting that will require an if statement. Some people
don't like them, but I occasionally used the iif() function for a simple
comparison like this.

iif(minute(startTime) NEQ
0),DE(timeFormat(startTime,"h:mm")),DE(timeFormat(startTime,"h")))

NOTE: No debugging done at all... confirm all syntax before usage.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 06, 2008 Oct 06, 2008
The string replace worked great. Thank you. However, it only worked for AM times. Is there a way to do it for PM as well? I tried a few things myself, but wasn't able to get it to work.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 06, 2008 Oct 06, 2008
Try lcase instead of replace.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 06, 2008 Oct 06, 2008
LATEST
Thanks for the tip. This works for both am/pm, but now I lose the periods (a.m./p.m.) Is there any way to get those back?
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources