DateTimePicker help

Started by Dan English, July 20, 2010, 07:44:58 PM

Previous topic - Next topic

Dan English

Does anyone know how to set a DateTimePicker control's value to a date that's contained in a string?

I've searched the forum and found how to set it to the current system date, but not to a specific date.

Thanks.

Paul Squires

Here you go....


    Dim DateRange As SYSTEMTIME

    DateRange.wYear      = 2010
    DateRange.wMonth     = 12
    DateRange.wDayOfWeek = 0
    DateRange.wDay       = 31
    DateRange.wHour      = 0
    DateRange.wMinute    = 0
    DateRange.wSecond    = 0

    SendMessage hWndControl, %DTM_SETSYSTEMTIME, %GDT_VALID, ByVal VarPtr(DateRange)


Paul Squires
PlanetSquires Software

Rolf Brandt

I am really fighting with this one. Does not work for me. Any idea how to set the date of a DateTimePicker Control????
Rolf Brandt
http://www.rbsoft.eu
http://www.taxifreeware.com
I cook with wine, sometimes I even add it to the food.
(W. C. Fields)

José Roca

See Paul's reply above. If it does not work for you, you must be using a wrong window handle.


Rolf Brandt

Thanks, Jose.

The code works of course. It was my own stupid fault.I used the code in a function which I had replaced with another - but forgot to remove the old one.Took me over an hour to find that out.
Rolf Brandt
http://www.rbsoft.eu
http://www.taxifreeware.com
I cook with wine, sometimes I even add it to the food.
(W. C. Fields)

Nathan Durland

Sorry I'm late to the game, here.  I wrote this some time ago.  Apologies to Paul for using the "FF_" prefix, but at the time it made training my assistant easier.


FUNCTION FF_SetDateTime(BYVAL TheCtl AS LONG, BYVAL TheDateTime AS STRING) AS LONG

  LOCAL st      AS SYSTEMTIME

  LOCAL TheDate, TheTime    AS STRING

  ' Date should be in MM-dd-yyyy format
  TheDate = EXTRACT$(TheDateTime, " ")
  TheTime = REMAIN$(TheDateTime, " ")

  st.wYear         = VAL(MID$(TheDate, 7, 4))
  st.wMonth        = VAL(MID$(TheDate, 1, 2))
  st.wDay          = VAL(MID$(TheDate, 4, 2))
  st.wHour         = 0
  st.wMinute       = 0
  st.wSecond       = 0
  st.wMilliseconds = 0
  IF LEN(TheTime) > 0 THEN
    TheTime    = TwentyFourHourTime(TheTime)
    st.wHour   = VAL(PARSE$(TheTime,":",1))
    st.wMinute = VAL(PARSE$(TheTime,":",2))
    st.wSecond = VAL(PARSE$(TheTime,":",3))
  END IF


  DateTime_SetSystemtime (TheCtl, 0, st)



END FUNCTION

FUNCTION TwentyFourHourTime(BYVAL t AS STRING) AS STRING
'-------------------------------------------------------------
'  This function converts a time string (01:15:00AM) to
'  24 hour (military) time.
'
'  04:00:00PM becomes 16:00:00
'  12:10:00AM becomes 00:10:00
'-------------------------------------------------------------
  LOCAL h,m,s       AS LONG
  LOCAL AM, PM      AS LONG


  t = UCASE$(t)
  PM = (INSTR(t,"P") > 0)
  AM = (INSTR(t,"A") > 0)

  t = RETAIN$(t, ANY "0123456789:")

  h = VAL(PARSE$(t,":",1))
  m = VAL(PARSE$(t,":",2))
  s = VAL(PARSE$(t,":",3))

  IF ISTRUE(PM) AND (h < 12) THEN h = h + 12
  IF ISTRUE(AM) AND (h = 12) THEN h = 0

  t = FORMAT$(h,"00") + ":" + FORMAT$(m,"00") + ":" + FORMAT$(s,"00")

  FUNCTION = t

END FUNCTION




Rolf Brandt

Thanks Nathan,

I had found that in the Forum too. My problem was that I put the code into the wrong function. And it took me a while to notice that.
Rolf Brandt
http://www.rbsoft.eu
http://www.taxifreeware.com
I cook with wine, sometimes I even add it to the food.
(W. C. Fields)