Jump to content

Converting a date Gui to a useable format


Zaxon
 Share

Recommended Posts

In every programming language I've used there is a common format that can be used by your date functions, and used in date calculations. Usually, it's the number of seconds since epoch.

Perhaps the commonest date format I've seen in AutoIt that is used in calcs is "YYYY/MM/DD[ HH:MM:SS]", and that's fine.

The _DateTimeFormat converts from that to other formats, but I'm yet to find a function that converts TO YYYY/MM/DD[ HH:MM:SS].

In particular, when a user enters a date or time via a GUICtrlCreateDate control, when you read it back it's in a non standard format - basically however your region date/time settings are configured. I need to convert from regional time back to the YYYY/MM/DD[ HH:MM:SS] for calcs. But, unless I'm overlooking it, there doesn't appear to be a function for doing this.

So short of manually pulling apart the region time (and writing a script that only works if it's on your computer or one set up identically), how do we convert from regional time to YYYY/MM/DD[ HH:MM:SS] format?

Link to comment
Share on other sites

using StringLeft and StringTrimLeft

[font="Times"] If anyone remembers me, I am back. Maybe to stay, maybe not.----------------------------------------------------------------------------------------------------------[/font][font="Times"]Things I am proud of: Pong! in AutoIt | SearchbarMy website: F.R.I.E.S.A little website that is trying to get started: http://thepiratelounge.net/ (not mine)[/font][font="Times"] ----------------------------------------------------------------------------------------------------------[/font][font="Arial"]The newbies need to stop stealing avatars!!! It is confusing!![/font]

Link to comment
Share on other sites

using StringLeft and StringTrimLeft

<{POST_SNAPBACK}>

That only divides the string into two. It doesn't take into account 12hr->24hr conversion, plus the different region setting which you cannot predict about the computing on which it's running. Although come to think of it, LOCALE_STIMEFORMAT etc may be fixed formats, although the help is vague saying produces a result like "blah", suggestion that the region settings of your PC may influence the way the date gui works.

There should be an inbuilt function that handles this extremely common conversion.

Link to comment
Share on other sites

There are many date functions, I don't really know what you're talking about honestly (not your fault, just never deal with Date/Time)

I DID make an Alarm Clock recently however, I used _NowTime(), which returns the HH:MM:SS, and there's probably a _NowDate() that returns what you want.

"I thoroughly disapprove of duels. If a man should challenge me, I would take him kindly and forgivingly by the hand and lead him to a quiet place and kill him." - Mark TwainPatient: "It hurts when I do $var_"Doctor: "Don't do $var_" - Lar.
Link to comment
Share on other sites

There are many date functions, I don't really know what you're talking about honestly (not your fault, just never deal with Date/Time)

<{POST_SNAPBACK}>

I forgive you.

I DID make an Alarm Clock recently however, I used _NowTime(), which returns the HH:MM:SS, and there's probably a _NowDate() that returns what you want.

<{POST_SNAPBACK}>

Yes, the now() functions play nicely, returning time in the proper format. But you can ask a user to select a date and time of their choosing, a bit like when you click on the windows clock in the bottom right hand corner of the system tray, and get a graphical calandar. So you my ask the user, "select the date and time of your next blah blah", and you'll get back a date or time, but in a different format.

We need to know the following:

* is the an inbuilt string to convert that to the calc format?

* I can certainly build one myself, but I hate to have to reinvent the wheel for something that absolutely should be able to be done already

* If I have to "role my own", I already know the date & time formats returned by the dategui WILL vary, according to how your personal regional settings are setup on your PC. That spells trouble for compatibility

Link to comment
Share on other sites

; This might help a little

;;; http://msdn.microsoft.com/library/default....m_setformat.asp

;;; http://msdn.microsoft.com/library/default....tp_format_chars

;;; Goal is YYYY/MM/DD[ HH:MM:SS]

#include <GUIConstants.au3>

GUICreate ( "My GUI get date", 200,200,800,200)

$date = GUICtrlCreateDate ("1953/04/25", 10,10,185,20 )

$style = "yyyy'/'MM'/'dd HH':'mm':'s"

GuiCtrlSendMsg($date, 0x1005, 0, $style)

GuiSetState()

While GuiGetMsg() <> $GUI_EVENT_CLOSE

WEnd

MsgBox(0,"Date",GUICtrlRead($date))

Time zone info can probably be gained from HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\TimeZoneInformation

Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig!
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...