Jump to content

Date & time functions in VBA. How to convert ?


Tany
 Share

Recommended Posts

There are many Date and Time functions in already built in AutoIt.

Like:

_Date_Time_GetSystemTime

_Now

_NowCalc

What exactly do you need to do?

Hi. I have seen all these available functions, but none is getting the y, m, d, h, n(minutes), s out of a date declared variable.

At least not so far as i could identify.

cheers,

T

Link to comment
Share on other sites

Hi. I have seen all these available functions, but none is getting the y, m, d, h, n(minutes), s out of a date declared variable.

At least not so far as i could identify.

cheers,

T

hm... I see there was a slip of the finger in the example :

In VBA it says :

n=now()

h=hour(n) h being y or m or d or h or n or s

in AutoIt this must be :

$n = _now()

$h = ???($n)

Link to comment
Share on other sites

Roll your own function dude, it's not difficult.

$timestamp = _NOW()
ConsoleWrite($timestamp & @CRLF)
ConsoleWrite("Year: " & _Year($timestamp) & @CRLF)
ConsoleWrite("Month: " & _Month($timestamp) & @CRLF)
ConsoleWrite("Day: " & _Day($timestamp) & @CRLF)
ConsoleWrite("Hour: " & _Hour($timestamp) & @CRLF)
ConsoleWrite("Minute: " & _Minute($timestamp) & @CRLF)
ConsoleWrite("Second: " & _Second($timestamp) & @CRLF)


Func _Now()
    Return StringFormat('%i-%02i-%02i %02i:%02i:%02i',@YEAR, @MON,@MDAY,@HOUR,@MIN,@SEC)
EndFunc

Func _Year($ts)
    Return StringMid($ts,1,4)
EndFunc

Func _Month($ts)
    Return StringMid($ts,6,2)
EndFunc

Func _Day($ts)
    Return StringMid($ts,9,2)
EndFunc

Func _Hour($ts)
    Return StringMid($ts,12,2)
EndFunc

Func _Minute($ts)
    Return StringMid($ts,15,2)
EndFunc

Func _Second($ts)
    Return StringMid($ts,18,2)
EndFunc
Link to comment
Share on other sites

Did you check the weaponx post ?

Like for example

$seconds=@SEC

Yes, I did. But I am looking to get the seconds/minutes/... out of a calculated variable which is including YMDHMS. The @-functions are an equivalent of the date or time function in VBA, but then limited to the component.

You could say that VBA seconds(now()) is equal to AutoIt @SEC.

I am looking to get the components out of the calculated variable.

Thks

T

Link to comment
Share on other sites

Yes, I did. But I am looking to get the seconds/minutes/... out of a calculated variable which is including YMDHMS. The @-functions are an equivalent of the date or time function in VBA, but then limited to the component.

You could say that VBA seconds(now()) is equal to AutoIt @SEC.

I am looking to get the components out of the calculated variable.

Thks

T

Sorry. I missed WeaponX. And OK this is a solution.

Only... I did not reached the mental state to imagin one has to program his own SquareRoot. These are standard functions in VBA... so I was searching for them, not for "roll your own function".

Thank you.

T

Link to comment
Share on other sites

Roll your own function dude, it's not difficult.

Thks MVP. Is indeed not difficult, but I did not reached the mental state to imagine one has to code his own SQUAREROOT.

Is standard functionality in VBA.

Looking for blood ? Like that. Me(a)t you in Wado Ruy dojo next week.

Cheers,

T

Link to comment
Share on other sites

  • Moderators

Tany,

but I did not reached the mental state to imagine one has to code his own SQUAREROOT

You do not have to - AutoIt can do that for you as you can see here:

ConsoleWrite(17^.5 & @CRLF)

Remember the very different roots of VBA and AutoIt. AutoIt is growing into a much more complete language than it used to be, but no-one pretends it is there yet. However, it gets closer and closer with every release. :mellow:

Just be pleased that you have a choice of language depending on what you want to do! :(

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

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...