Format date/time in DTPicker to display AM/PM or 24 hour time 
Author Message
 Format date/time in DTPicker to display AM/PM or 24 hour time

Hi,

Does anyone know how to format the DTPicker control to display a date
with a time showing either AM/PM or using 24 hour time?

I've tried just about everything you would normally use to format a
time with no success. I would've thought it would be something like
dd/MM/yyyy h:mm AM/PM but no go. I'm sure I've done this before with
no problems but for the life of me can't remember or find out how! Is
there some trick to it?

Thanks for any insight.

Mong



Sun, 25 Sep 2005 08:32:28 GMT  
 Format date/time in DTPicker to display AM/PM or 24 hour time

Private Sub Command1_Click()

  '24-hour time
   With DTPicker1
      .Format = dtpCustom
      .CustomFormat = "HH.mm"
      .Refresh
   End With

End Sub

Private Sub Command2_Click()

  '12-hour time w/am-pm
   With DTPicker1
      .Format = dtpCustom
      .CustomFormat = "hh.mm tt"
      .Refresh
   End With

End Sub

Private Sub Command3_Click()

  '12-hour time w/o am-pm
   With DTPicker1
      .Format = dtpCustom
      .CustomFormat = "hh.mm"
      .Refresh
   End With

End Sub

--

Randy Birch
MVP Visual Basic
http://www.mvps.org/vbnet/
Please respond only to the newsgroups so all can benefit.


: Hi,
:
: Does anyone know how to format the DTPicker control to display a date
: with a time showing either AM/PM or using 24 hour time?
:
: I've tried just about everything you would normally use to format a
: time with no success. I would've thought it would be something like
: dd/MM/yyyy h:mm AM/PM but no go. I'm sure I've done this before with
: no problems but for the life of me can't remember or find out how! Is
: there some trick to it?
:
: Thanks for any insight.
:
: Mong



Sun, 25 Sep 2005 08:55:36 GMT  
 Format date/time in DTPicker to display AM/PM or 24 hour time
Thanks Randy but as I said I had tried everything before I posted
here. Just wondering, did you try this example on your machine and if
so did it work? I can use H:mm to get 24hr time so I'll just have to
use that. Sure I've used AM/PM before though!
Quote:

> Private Sub Command1_Click()

>   '24-hour time
>    With DTPicker1
>       .Format = dtpCustom
>       .CustomFormat = "HH.mm"
>       .Refresh
>    End With

> End Sub

> Private Sub Command2_Click()

>   '12-hour time w/am-pm
>    With DTPicker1
>       .Format = dtpCustom
>       .CustomFormat = "hh.mm tt"
>       .Refresh
>    End With

> End Sub

> Private Sub Command3_Click()

>   '12-hour time w/o am-pm
>    With DTPicker1
>       .Format = dtpCustom
>       .CustomFormat = "hh.mm"
>       .Refresh
>    End With

> End Sub

> --

> Randy Birch
> MVP Visual Basic
> http://www.mvps.org/vbnet/
> Please respond only to the newsgroups so all can benefit.



> : Hi,
> :
> : Does anyone know how to format the DTPicker control to display a date
> : with a time showing either AM/PM or using 24 hour time?
> :
> : I've tried just about everything you would normally use to format a
> : time with no success. I would've thought it would be something like
> : dd/MM/yyyy h:mm AM/PM but no go. I'm sure I've done this before with
> : no problems but for the life of me can't remember or find out how! Is
> : there some trick to it?
> :
> : Thanks for any insight.
> :
> : Mong



Sun, 25 Sep 2005 13:25:13 GMT  
 Format date/time in DTPicker to display AM/PM or 24 hour time
I don't think you tried everything <g>. If you had checked the help
files for the DatePicker control, specifically the CustomFormat
property, you would have seen that the meta-characters for AM/PM are tt
(two letter t's next to each other) and t (one, single letter t) for A/P
style.

Rick - MVP


Quote:
> Thanks Randy but as I said I had tried everything before I posted
> here. Just wondering, did you try this example on your machine and if
> so did it work? I can use H:mm to get 24hr time so I'll just have to
> use that. Sure I've used AM/PM before though!




Quote:
> > Private Sub Command1_Click()

> >   '24-hour time
> >    With DTPicker1
> >       .Format = dtpCustom
> >       .CustomFormat = "HH.mm"
> >       .Refresh
> >    End With

> > End Sub

> > Private Sub Command2_Click()

> >   '12-hour time w/am-pm
> >    With DTPicker1
> >       .Format = dtpCustom
> >       .CustomFormat = "hh.mm tt"
> >       .Refresh
> >    End With

> > End Sub

> > Private Sub Command3_Click()

> >   '12-hour time w/o am-pm
> >    With DTPicker1
> >       .Format = dtpCustom
> >       .CustomFormat = "hh.mm"
> >       .Refresh
> >    End With

> > End Sub

> > --

> > Randy Birch
> > MVP Visual Basic
> > http://www.mvps.org/vbnet/
> > Please respond only to the newsgroups so all can benefit.



> > : Hi,
> > :
> > : Does anyone know how to format the DTPicker control to display a
date
> > : with a time showing either AM/PM or using 24 hour time?
> > :
> > : I've tried just about everything you would normally use to format
a
> > : time with no success. I would've thought it would be something
like
> > : dd/MM/yyyy h:mm AM/PM but no go. I'm sure I've done this before
with
> > : no problems but for the life of me can't remember or find out how!
Is
> > : there some trick to it?
> > :
> > : Thanks for any insight.
> > :
> > : Mong



Sun, 25 Sep 2005 16:01:14 GMT  
 Format date/time in DTPicker to display AM/PM or 24 hour time
Yes, and yes.

--

Randy Birch
MVP Visual Basic
http://www.mvps.org/vbnet/
Please respond only to the newsgroups so all can benefit.


: Thanks Randy but as I said I had tried everything before I posted
: here. Just wondering, did you try this example on your machine and if
: so did it work? I can use H:mm to get 24hr time so I'll just have to
: use that. Sure I've used AM/PM before though!
:


: > Private Sub Command1_Click()
: >
: >   '24-hour time
: >    With DTPicker1
: >       .Format = dtpCustom
: >       .CustomFormat = "HH.mm"
: >       .Refresh
: >    End With
: >
: > End Sub
: >
: >
: > Private Sub Command2_Click()
: >
: >   '12-hour time w/am-pm
: >    With DTPicker1
: >       .Format = dtpCustom
: >       .CustomFormat = "hh.mm tt"
: >       .Refresh
: >    End With
: >
: > End Sub
: >
: >
: > Private Sub Command3_Click()
: >
: >   '12-hour time w/o am-pm
: >    With DTPicker1
: >       .Format = dtpCustom
: >       .CustomFormat = "hh.mm"
: >       .Refresh
: >    End With
: >
: > End Sub
: >
: >
: >
: >
: >
: > --
: >
: > Randy Birch
: > MVP Visual Basic
: > http://www.mvps.org/vbnet/
: > Please respond only to the newsgroups so all can benefit.
: >
: >


: > : Hi,
: > :
: > : Does anyone know how to format the DTPicker control to display a date
: > : with a time showing either AM/PM or using 24 hour time?
: > :
: > : I've tried just about everything you would normally use to format a
: > : time with no success. I would've thought it would be something like
: > : dd/MM/yyyy h:mm AM/PM but no go. I'm sure I've done this before with
: > : no problems but for the life of me can't remember or find out how! Is
: > : there some trick to it?
: > :
: > : Thanks for any insight.
: > :
: > : Mong



Mon, 26 Sep 2005 05:48:07 GMT  
 Format date/time in DTPicker to display AM/PM or 24 hour time
Ok, I've been developing in VB for 6 years and I learnt how to use the
VB help files at uni 10 years ago so I'm well aware of what tt (two
lower case letter t's next to each other) means to the CustomFormat
property of a DTPicker control. Obviously you haven't been in the
trade very long else you wouldn't be assuming things like what the
help files say go! <g>

As I said I have used this successfully before (without consulting the
magic help file too!) on other contracts which leads me to believe the
problem is local hence the need to post to this group. I'm hoping that
someone else may have come across it.

I know you guys are trying to help and I appreciate that but please
don't post any more obvious solutions. Perhaps you should assume that
these have all been exhausted before the last resort of posting here.

Bottom line is: CustomFormat = "dd/MM/yyyy h:mm tt" does not work
correctly. Maybe on your machine but not on this one. Believe me.

Version info:
VB6 SP5
DTPicker -> mscomct2.ocx 6.0.88.4

Perhaps I need to clarify my question - I mean why not how.

Thanks for any help.

Quote:

> I don't think you tried everything <g>. If you had checked the help
> files for the DatePicker control, specifically the CustomFormat
> property, you would have seen that the meta-characters for AM/PM are tt
> (two letter t's next to each other) and t (one, single letter t) for A/P
> style.

> Rick - MVP



> > Thanks Randy but as I said I had tried everything before I posted
> > here. Just wondering, did you try this example on your machine and if
> > so did it work? I can use H:mm to get 24hr time so I'll just have to
> > use that. Sure I've used AM/PM before though!



> > > Private Sub Command1_Click()

> > >   '24-hour time
> > >    With DTPicker1
> > >       .Format = dtpCustom
> > >       .CustomFormat = "HH.mm"
> > >       .Refresh
> > >    End With

> > > End Sub

> > > Private Sub Command2_Click()

> > >   '12-hour time w/am-pm
> > >    With DTPicker1
> > >       .Format = dtpCustom
> > >       .CustomFormat = "hh.mm tt"
> > >       .Refresh
> > >    End With

> > > End Sub

> > > Private Sub Command3_Click()

> > >   '12-hour time w/o am-pm
> > >    With DTPicker1
> > >       .Format = dtpCustom
> > >       .CustomFormat = "hh.mm"
> > >       .Refresh
> > >    End With

> > > End Sub

> > > --

> > > Randy Birch
> > > MVP Visual Basic
> > > http://www.mvps.org/vbnet/
> > > Please respond only to the newsgroups so all can benefit.



> > > : Hi,
> > > :
> > > : Does anyone know how to format the DTPicker control to display a
>  date
> > > : with a time showing either AM/PM or using 24 hour time?
> > > :
> > > : I've tried just about everything you would normally use to format
>  a
> > > : time with no success. I would've thought it would be something
>  like
> > > : dd/MM/yyyy h:mm AM/PM but no go. I'm sure I've done this before
>  with
> > > : no problems but for the life of me can't remember or find out how!
>  Is
> > > : there some trick to it?
> > > :
> > > : Thanks for any insight.
> > > :
> > > : Mong



Mon, 26 Sep 2005 08:13:14 GMT  
 Format date/time in DTPicker to display AM/PM or 24 hour time
Sorry about the "attitude"; I was only trying to have some fun... sorry.

Now, you are saying this doesn't work, right?

Private Sub Form_Load()
  With DTPicker1
    .CustomFormat = "dd/MM/yyyy h:mm tt"
    .Format = dtpCustom
  End With
End Sub

You say you are using VB6, what Service Pack level and Windows version
are you using? (Knowing these probably won't help me, but it might help
someone else figure out what's going on.) For your use and information
in trying to solve your problem, the above code worked perfectly on my
VB6SP3 on Win98SE system.

Rick - MVP


Quote:
> Ok, I've been developing in VB for 6 years and I learnt how to use the
> VB help files at uni 10 years ago so I'm well aware of what tt (two
> lower case letter t's next to each other) means to the CustomFormat
> property of a DTPicker control. Obviously you haven't been in the
> trade very long else you wouldn't be assuming things like what the
> help files say go! <g>

> As I said I have used this successfully before (without consulting the
> magic help file too!) on other contracts which leads me to believe the
> problem is local hence the need to post to this group. I'm hoping that
> someone else may have come across it.

> I know you guys are trying to help and I appreciate that but please
> don't post any more obvious solutions. Perhaps you should assume that
> these have all been exhausted before the last resort of posting here.

> Bottom line is: CustomFormat = "dd/MM/yyyy h:mm tt" does not work
> correctly. Maybe on your machine but not on this one. Believe me.

> Version info:
> VB6 SP5
> DTPicker -> mscomct2.ocx 6.0.88.4

> Perhaps I need to clarify my question - I mean why not how.

> Thanks for any help.




- Show quoted text -

Quote:
> > I don't think you tried everything <g>. If you had checked the help
> > files for the DatePicker control, specifically the CustomFormat
> > property, you would have seen that the meta-characters for AM/PM are
tt
> > (two letter t's next to each other) and t (one, single letter t) for
A/P
> > style.

> > Rick - MVP



> > > Thanks Randy but as I said I had tried everything before I posted
> > > here. Just wondering, did you try this example on your machine and
if
> > > so did it work? I can use H:mm to get 24hr time so I'll just have
to
> > > use that. Sure I've used AM/PM before though!




- Show quoted text -

Quote:
> > > > Private Sub Command1_Click()

> > > >   '24-hour time
> > > >    With DTPicker1
> > > >       .Format = dtpCustom
> > > >       .CustomFormat = "HH.mm"
> > > >       .Refresh
> > > >    End With

> > > > End Sub

> > > > Private Sub Command2_Click()

> > > >   '12-hour time w/am-pm
> > > >    With DTPicker1
> > > >       .Format = dtpCustom
> > > >       .CustomFormat = "hh.mm tt"
> > > >       .Refresh
> > > >    End With

> > > > End Sub

> > > > Private Sub Command3_Click()

> > > >   '12-hour time w/o am-pm
> > > >    With DTPicker1
> > > >       .Format = dtpCustom
> > > >       .CustomFormat = "hh.mm"
> > > >       .Refresh
> > > >    End With

> > > > End Sub

> > > > --

> > > > Randy Birch
> > > > MVP Visual Basic
> > > > http://www.mvps.org/vbnet/
> > > > Please respond only to the newsgroups so all can benefit.



> > > > : Hi,
> > > > :
> > > > : Does anyone know how to format the DTPicker control to display
a
> >  date
> > > > : with a time showing either AM/PM or using 24 hour time?
> > > > :
> > > > : I've tried just about everything you would normally use to
format
> >  a
> > > > : time with no success. I would've thought it would be something
> >  like
> > > > : dd/MM/yyyy h:mm AM/PM but no go. I'm sure I've done this
before
> >  with
> > > > : no problems but for the life of me can't remember or find out
how!
> >  Is
> > > > : there some trick to it?
> > > > :
> > > > : Thanks for any insight.
> > > > :
> > > > : Mong



Mon, 26 Sep 2005 10:25:52 GMT  
 Format date/time in DTPicker to display AM/PM or 24 hour time
Yep, even cut and paste it into my form (change control name ofcourse)
so it was like this:

Private Sub Form_Load()
    dtStart = Now()
    With dtStart
      .CustomFormat = "dd/MM/yyyy h:mm tt"
      .Format = dtpCustom
    End With
End Sub

Result: 10/04/2003 4:02

VB6 SP5 Windows 2000 Professional

I give up it's obviously local to this setup so I'll just use 24hr
time format.

Thanks anyway!

Quote:

> Sorry about the "attitude"; I was only trying to have some fun... sorry.

> Now, you are saying this doesn't work, right?

> Private Sub Form_Load()
>   With DTPicker1
>     .CustomFormat = "dd/MM/yyyy h:mm tt"
>     .Format = dtpCustom
>   End With
> End Sub

> You say you are using VB6, what Service Pack level and Windows version
> are you using? (Knowing these probably won't help me, but it might help
> someone else figure out what's going on.) For your use and information
> in trying to solve your problem, the above code worked perfectly on my
> VB6SP3 on Win98SE system.

> Rick - MVP



> > Ok, I've been developing in VB for 6 years and I learnt how to use the
> > VB help files at uni 10 years ago so I'm well aware of what tt (two
> > lower case letter t's next to each other) means to the CustomFormat
> > property of a DTPicker control. Obviously you haven't been in the
> > trade very long else you wouldn't be assuming things like what the
> > help files say go! <g>

> > As I said I have used this successfully before (without consulting the
> > magic help file too!) on other contracts which leads me to believe the
> > problem is local hence the need to post to this group. I'm hoping that
> > someone else may have come across it.

> > I know you guys are trying to help and I appreciate that but please
> > don't post any more obvious solutions. Perhaps you should assume that
> > these have all been exhausted before the last resort of posting here.

> > Bottom line is: CustomFormat = "dd/MM/yyyy h:mm tt" does not work
> > correctly. Maybe on your machine but not on this one. Believe me.

> > Version info:
> > VB6 SP5
> > DTPicker -> mscomct2.ocx 6.0.88.4

> > Perhaps I need to clarify my question - I mean why not how.

> > Thanks for any help.



> > > I don't think you tried everything <g>. If you had checked the help
> > > files for the DatePicker control, specifically the CustomFormat
> > > property, you would have seen that the meta-characters for AM/PM are
>  tt
> > > (two letter t's next to each other) and t (one, single letter t) for
>  A/P
> > > style.

> > > Rick - MVP



> > > > Thanks Randy but as I said I had tried everything before I posted
> > > > here. Just wondering, did you try this example on your machine and
>  if
> > > > so did it work? I can use H:mm to get 24hr time so I'll just have
>  to
> > > > use that. Sure I've used AM/PM before though!



> > > > > Private Sub Command1_Click()

> > > > >   '24-hour time
> > > > >    With DTPicker1
> > > > >       .Format = dtpCustom
> > > > >       .CustomFormat = "HH.mm"
> > > > >       .Refresh
> > > > >    End With

> > > > > End Sub

> > > > > Private Sub Command2_Click()

> > > > >   '12-hour time w/am-pm
> > > > >    With DTPicker1
> > > > >       .Format = dtpCustom
> > > > >       .CustomFormat = "hh.mm tt"
> > > > >       .Refresh
> > > > >    End With

> > > > > End Sub

> > > > > Private Sub Command3_Click()

> > > > >   '12-hour time w/o am-pm
> > > > >    With DTPicker1
> > > > >       .Format = dtpCustom
> > > > >       .CustomFormat = "hh.mm"
> > > > >       .Refresh
> > > > >    End With

> > > > > End Sub

> > > > > --

> > > > > Randy Birch
> > > > > MVP Visual Basic
> > > > > http://www.mvps.org/vbnet/
> > > > > Please respond only to the newsgroups so all can benefit.



> > > > > : Hi,
> > > > > :
> > > > > : Does anyone know how to format the DTPicker control to display
>  a
>  date
> > > > > : with a time showing either AM/PM or using 24 hour time?
> > > > > :
> > > > > : I've tried just about everything you would normally use to
>  format
>  a
> > > > > : time with no success. I would've thought it would be something
>  like
> > > > > : dd/MM/yyyy h:mm AM/PM but no go. I'm sure I've done this
>  before
>  with
> > > > > : no problems but for the life of me can't remember or find out
>  how!
>  Is
> > > > > : there some trick to it?
> > > > > :
> > > > > : Thanks for any insight.
> > > > > :
> > > > > : Mong



Mon, 26 Sep 2005 14:04:56 GMT  
 
 [ 8 post ] 

 Relevant Pages 

1. 24 hour time format

2. 24 hour time format

3. Time Format >24 Hours

4. Help - FORCE TIME FORMAT TO BE 24 HOUR ??

5. Time function, displaying AM PM

6. Calculating time values >24 HOURS

7. Help: 24-hour time

8. 24 Hour Time

9. Adding Times That Exceed 24 hours???

10. 24 hour time

11. HELP: Convert Number to Time and Display in 12 Hour Format

12. Need function to increase time in date/time field by one hour

 

 
Powered by phpBB® Forum Software