Jump to content

Date Time format conversion


Recommended Posts

hi,

i need your great help to convert the following:

after running my script, i get the following output:

2006/08/21 16:40:08

how do i actually convert this so that the output reads as such for my second command?

21/08/2006 4:40 PM

thanks.

mouse not found....scroll any mouse to continue.

Link to comment
Share on other sites

Would be easier if we had a few lines to work with... But.. try something like this:

$date = "2006/08/21"
$temp1 = StringLeft($Date,4)
$temp2 = StringMid($Date,6,2)
$temp3 = StringRight($Date,2)
$Date = $Temp3 &"/"& $Temp2 &"/"& $Temp1
msgbox(0,"",$Date)

$time = "16:40:08"
$Temp1 = StringLeft($time,2)
$Temp2 = StringMid($time,4,2)
If $temp1 > 12 Then $Temp1 = $temp1 - 12
$time = $Temp1 &":"& $Temp2
msgbox(0,"", $time)

Pretty lame way to do it though, theres probrably a time/date format option somewhere

Edited by Rad
Link to comment
Share on other sites

What is your current script? To get in it 12 hour format simply do the Hour - 12 (ie. 16 - 12 = 4). As for the Day/Month/Year, use StringSplit() and re-order them or change the regional settings on your computer. Seek the helpfile's "Date Management" catergory in Contents for further enlightenment :P. Edited by Larry

qq

Link to comment
Share on other sites

  • Developers

why not do it the ease way when you want to convert it to the PC's Date/Time format ?

#include<date.au3>
$NewDate = _DateTimeFormat("2006/08/21 16:40:08",0)

:P

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

Link to comment
Share on other sites

Hi,

Of course, if you are asking for your output in your local settings;

$sDate="2006/08/21 16:40:08"
MsgBox( 4096, "_DateTimeFormat ( $sDate, 0)=", ""&_DateTimeFormat ( $sDate, 0))
If not, you'll have to parse.

best, randall

Link to comment
Share on other sites

thanks for all the replies guys.

well here is what i wanna do actually....need BETA for this.

AutoItSetOption("TrayIconHide", 1)

#include <GUIConstants.au3>
#include <File.au3>
#include <Date.au3>

$passwd = InputBox("Security Check - Login", "Please enter your password.", "", "x", 200, 130)
If $passwd = ("password") Then
    
$c1 = InputBox("Details", "Please Enter Your Name.")
$c2 = InputBox("Details", "Please Enter Your Login ID.")
    
If @error = 1 Then Exit
$search = FileFindFirstFile("p*.txt")
    
If $search = -1 Then
MsgBox(16, "Error", "No files/directories matched the search pattern.")
Exit
EndIf

$i = 0
$m = 0
$s = 0
    
While 1
    
SplashTextOn("", " Please wait . . . modifications in progress. " & @CRLF & @CRLF & "Number of files processed: " & $i, 260, 55, -1, -1, 3, "", 10)
$file = FileFindNextFile($search)
If @error Then ExitLoop
    
$sNewDate1 = _DateAdd( 'n', $m, _NowCalc())
$sNewDate2 = _DateAdd( 's', $s, $sNewDate1)
$val = _DateTimeFormat($sNewDate2, 3)
    
_FileWriteToLine($file, 1, "Name: " & $c1, 1)
_FileWriteToLine($file, 2, "Execution: " & _NowDate() & " " & $val, 1)
_FileWriteToLine($file, 7, "Login: " & $c2, 1)

FileSetTime("file pattern", "time", 0, 0); ???!!!THIS IS WHERE MY PROBLEM IS!!!???

$i = $i + 1
$m = $m + 3
$s = $s + 27
    
WEnd

SplashOff()

FileClose($search)

MsgBox(0, "End", $i & " files have been modified successfully.")
Exit

Else
MsgBox(16, "Warning!", "Login Failed - Access Denied")
EndIf

Line 39 gives me problem.

Line 2 of the output text file must be in this format : "Execution: 8/21/2006 5:02:54 PM"

I can get line 2 right.

But I need the time in line 2 to be set as the FileSetTime (modified) for the files. Each file has a diff time in line 2 and therefore I also need the diff File Stamping times. I just can't work with this conversions. FileSetTime requires the format to be YYYYMMDDHHMMSS. Hence the problem, i think....

Please kindly assist.

Thanks.

Edited by iceberg

mouse not found....scroll any mouse to continue.

Link to comment
Share on other sites

OK,

Maybe;

$val =StringReplace(StringReplace(_DateTimeFormat($sNewDate2, 2)& _DateTimeFormat($sNewDate2, 5),"/",""),":","")
MsgBox(0,"","$val="&$val)
FileSetTime($file,$val, 0, 0); ???!!!THIS IS WHERE MY PROBLEM IS!!!???
Best, Randall
Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
 Share

  • Recently Browsing   0 members

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