Sign in to follow this  
Followers 0
fgilain

Datediff problem between windows and Linux machine ?

14 posts in this topic

Hello,

I need to create a script using autoit on a windows computer to execute it on a remote linux server using putty (or plink) and this script needs to generate a string corresponding to the actuel date/time in the linux format (equivalent to the linux command : `/bin/date +%s`).

My problem is that it seems to generate it with 1 hour more than it should be..

maybe did i missed something ? here is the code i used :

$UnixDateSince1970 = _DateDiff( 's',"1970/01/01 00:00:00",_NowCalc())

Any idea of what i coul have missed ?

Nb : actually, it's 2013/02/22 01:20PM in France, and the result string is : 1361539258

thanks

Florent

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

on the linux server, result is :

[root@remote_linux_server]# date

ven fév 22 13:22:20 CET 2013

[root@remote_linux_server]# date

ven fév 22 13:22:20 CET 2013

[root@remote_linux_server]# date

ven fév 22 13:22:20 CET 2013

[root@remote_linux_server]# /bin/date +%s

1361535757

seems to have 1 hour of difference too in the result ???? should i change something about the "CET" timezone somewhere on the linux ?

Edited by fgilain

Share this post


Link to post
Share on other sites

What do you get if you run "date" on the linux machine? Is it GMT time?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

1 hour might be difference from UTC to local time or daylight savings.

Sorting out which is which is up to you since we have no idea of both machines' settings.

1 person likes this

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites

Seems you can specify the timezone in the datestr:

"Sets the time and date to the value specfied in the datestr. The datestr may contain the month names, timezones, 'am', 'pm', etc. See examples for an example of how the date and time can be set."


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Here is a complete list of format control characters supported by date command.

Add the timezone and see if the result changes.

Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

[root@remote_linux_server]# date

ven fév 22 18:14:18 CET 2013

[root@remote_linux_server]# date -u

ven fév 22 17:20:55 UTC 2013

Edited by fgilain

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

Solution would be to get the "now date" from autoit in UTC format, no ?

Because actually it seems to return the GMT+1 datetime....

And what will happen at next change of hour here in france ?

Edited by fgilain

Share this post


Link to post
Share on other sites

fgilain,

Most users would want the local time - so that is what Autoit gives you. But you can use _Date_Time_GetTimeZoneInformation and convert to UTC yourself - look at the Help file to see how. ;)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

Sorry, i'm not a "professional developer"...i'm quite lost in all theses expert solutions...

As i need to generate from my windows computer a string representing the actual time (since 1970) that would be the same as if i had calculated it on my linux box (even if there were daylight saving changes), what would be the best way then ?

NB :today, i just did a "- 3600" to my result to remove 1 hour in the result of my windows computer (but i suppose it won't work anymore after the next daylight change here in france ?)

Edited by fgilain

Share this post


Link to post
Share on other sites

fgilain,

This should do the trick: ;)

#include <Date.au3>

; Get local time
$sLocal_Time = _NowTime()
ConsoleWrite($sLocal_Time & @CRLF)
; Get time zone info - look in Help file to see what is in the different elements
$aTime_Info = _Date_Time_GetTimeZoneInformation()
; Convert local to UTC - you need to add the date to get the correct format
$sUTC_DTG = _DateAdd("n", $aTime_Info[1], _NowCalcDate() & " " & $sLocal_Time)
; Split the returned date and time
$aUTC = StringSplit($sUTC_DTG, " ")
; And we have UTC time
$sUTC_Time = $aUTC[2]
ConsoleWrite($sUTC_Time & @CRLF)

Does it? :huh:

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites

Seems to calculate correcly the time (1 hour less in UTC time) ..but what i really need is the "epoch datetime"...

NB : will htis work too after next daylight change ?

FG

Share this post


Link to post
Share on other sites

fgilain,

So write your own function to obtain epoch time - DateDiff looks like a good place to start. ;)

I have no idea if _Date_Time_GetTimeZoneInformation takes account of the twice yearly time changes - but if you look at the Help file page for the function you can see that there is a field for daylight saving, so I imagine it probably does. You will just have to wait and see. :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites

fgilain,

You could set the date/time on some PC to whatever date you want to test and watch it rollover...

kylomas


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
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
Sign in to follow this  
Followers 0