Jump to content
Sign in to follow this  
laurin1

Convert Date and Time to Seconds

Recommended Posts

MHz

You can copy the UDF from here.

Just a small sample to use, with the included UDF

$sType='s'
$sStartDate='2004/12/01 12:00:00'
$sEndDate='2004/12/01 12:01:00'
$ans= _DateDiff($sType, $sStartDate, $sEndDate)
MsgBox(0, 'Seconds', 'Equals ' & $ans)

Share this post


Link to post
Share on other sites
laurin1

You can copy the UDF from here.

Just a small sample to use, with the included UDF

$sType='s'
$sStartDate='2004/12/01 12:00:00'
$sEndDate='2004/12/01 12:01:00'
$ans= _DateDiff($sType, $sStartDate, $sEndDate)
MsgBox(0, 'Seconds', 'Equals ' & $ans)

<{POST_SNAPBACK}>

I don't understand. When I run your sample, the answer is 60. I want to take a date and convert it into seconds.

Keith Davis

MCSA, ZCE, A+, N+

http://www.laurinkeithdavis.com

Share this post


Link to post
Share on other sites
MHz

$sType is the variable for hours, minutes or seconds selection.

$sStartDate is the variable for Start Date.

$sEndDate is the variable for Finish Date.

$ans is the result of into the UDF script to create the difference in seconds, between the 2 dates.

The 60 returned is 60 seconds.

This gives you date/time difference in seconds?

Could you express more, if insuffient.

Share this post


Link to post
Share on other sites
Jos

I don't understand. When I run your sample, the answer is 60. I want to take a date and convert it into seconds.

<{POST_SNAPBACK}>

You will need a start date to determine the number of seconds elapsed since...

The Date functions currently only accept a date between 1900 - 2999 .


SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites
laurin1

You will need a start date to determine the number of seconds elapsed since...

The Date functions currently only accept a date between 1900 - 2999 .

<{POST_SNAPBACK}>

Oh, yea. Duh.

:idiot:


Keith Davis

MCSA, ZCE, A+, N+

http://www.laurinkeithdavis.com

Share this post


Link to post
Share on other sites
MHz

This is the area of interest in the UDF

; Description:      Returns the difference between 2 dates, expressed in the type requested

; Parameter(s):    $sType - returns the difference in:

;                              d = days

;                              m = Months

;                              y = Years

;                              w = Weeks

;                              h = Hours

;                              n = Minutes

;                              s = Seconds

;                  $sStartDate    - Input Start date in the format "YYYY/MM/DD[ HH:MM:SS]"

;                  $sEndDate    - Input End date in the format "YYYY/MM/DD[ HH:MM:SS]"

; Requirement(s):  None

; Return Value(s):  On Success - Difference between the 2 dates

;                  On Failure - 0  and Set

;                                  @ERROR to:  1 - Invalid $sType

;                                              2 - Invalid $sStartDate

;                                              3 - Invalid $sEndDate

; Author(s):        Jos van der Zande

JdeB coded it, btw. :idiot:

Share this post


Link to post
Share on other sites
the_lord_mephy

I don't understand how you can convert a Date into seconds. maybe Time, but date from when?


My site for HTML Help :)[quote name='Valik' date='Oct 15 2004, 12:29 PM']Maybe nobody is an "elite uber-coder" like me because thinking is a capital offense in today's online-world?[right][snapback]36427[/snapback][/right][/quote]

Share this post


Link to post
Share on other sites
Valik

Read the thread, that was answered. :idiot:

Edit: The common epoch is January 1, 1970 00:00:00 GMT.

Edited by Valik

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  

×