Page 1 of 1

Return Datestamp

Posted: Fri Feb 20, 2015 8:38 am
by djrikki

Code: Select all

<?xml version="1.0" ?>
<CodeBench_Project name="MUI Builder" path="DH1:Home Directory/Application Files/Development/MUI Builder/MUI Builder.cbp" created="1165340540" lastmodified="1171956807">
	<plugin name="PROGDIR:Plugins/Hollywood4.CCPlugin" flags="64" exetype="0" mainscript="main.hws"/>

Code: Select all

<?xml version="1.0" ?>
<CodeBench_Project name="Application Name" path="RAM:Application Name.cbp" created="20-Feb-2015 07:33:40" lastmodified="20-Feb-2015 07:33:40">
	<plugin name="PROGDIR:Plugins/Hollywood4.CCPlugin" flags="64" exetype="0" mainscript="main.hws"/>
Checkout the second line on each code example above, how do I generate the long numerical datestamp for both the 'created' and 'lastmodified' fields?

As you can see in the above example I am using GetDateNum(#DATETIME) which clearly doesn't have the desired result.

Re: Return Datestamp

Posted: Sat Feb 21, 2015 11:58 am
by airsoftsoftwair
What do you mean by "long numerical timestamp"? What exactly do you want to have?

Re: Return Datestamp

Posted: Sat Feb 21, 2015 1:16 pm
by jalih
airsoftsoftwair wrote:What do you mean by "long numerical timestamp"? What exactly do you want to have?
My guess would have been Unix time stamp, but as the numerical stamp on the first code box don't match with the date and time on the second code box... I am not really sure...

Anyway, code to convert to Unix time stamp would be something like:

Code: Select all

; Based on BlitzMax code by Zethrax
Function ToUnixTime(date, time)
  Local date = SplitStr(date, ".")
  Local time = SplitStr(time, ":")

  Local days = ToNumber(date[0])
  Local year = ToNumber(date[2])
  Local month = ToNumber(date[1])

  Local end_year
  If month > 2
	  end_year = year
  Else
	  end_year = year - 1
  EndIf

  For Local y = 1970 To end_year
	  If Mod(y, 100) = 0
		  If Mod(y, 400) = 0
			  days = days + 1
		  EndIf
	  ElseIf Mod(y, 4) = 0
		  days = days + 1
	  EndIf
  Next 

  days = days + (year - 1970) * 365

  If month > 1 Then days = days + 31
  If month > 2 Then days = days + 28
  If month > 3 Then days = days + 31
  If month > 4 Then days = days + 30
  If month > 5 Then days = days + 31
  If month > 6 Then days = days + 30
  If month > 7 Then days = days + 31
  If month > 8 Then days = days + 31
  If month > 9 Then days = days + 30
  If month > 10 Then days = days + 31
  If month > 11 Then days = days + 30
  If month > 12 Then days = days + 31

  Local hour = ToNumber(time[0])
  Local minutes = ToNumber(time[1])
  Local seconds = ToNumber(time[2])
  
  Return(days * 86400 + hour * 3600 + minutes * 60 + seconds)
EndFunction
You can test it with the following code and use some converter available on net to verify the result.

Code: Select all

DebugPrint(ToUnixTime(GetDate(), GetTime(True)))

Re: Return Datestamp

Posted: Sat Feb 21, 2015 6:25 pm
by djrikki
I was being quite literal with that description. I don't know how this number is arrived at. Its Simon Archer aka Rico who created Codebench. I'll ask him.

Re: Return Datestamp

Posted: Sun Feb 22, 2015 10:13 am
by airsoftsoftwair
It's probably an Amiga timestamp. They're not compatible to Unix timestamps because Unix time starts on January 1st, 1970 whereas Amiga time starts on January 1st, 1978. You could use jalih's code and adjust it to Amiga time, though.