Jump to content

How to add random seconds to Date/Time?


jmp
 Share

Go to solution Solved by mikell,

Recommended Posts

38 minutes ago, jmp said:

How?

my case, I don't need seconds and space between minutes and AM/PM also

This is a forum with volunteers, not a 24/7 paid support hotline. You should have no problems adjusting these minor details based on the examples. Please show a little more commitment and don't expect us to spoon-feed you.

Since I don't like to endorse indolence, I'm out of here.

Musashi-C64.png

"In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move."

Link to comment
Share on other sites

You might also try the screwy way - meaning regex (what else ?)  :idiot:

#include <Date.au3>

$sDateTime = "25/12/2023 18:50:30"

$res = Execute("'" & StringRegExpReplace($sDateTime, "(\d+)/(\d+)/(\d+) (\d+):(\d+).*", _ 
    "' & _DateToMonth('$2',1) & ' $1 $3 ' & ('$4'>12 ? StringFormat('%02i', '$4'-12) & ':$5PM' : '$4:$5AM') & '") & "'") 

Msgbox(0,"", $res)

 

Link to comment
Share on other sites

1 minute ago, mikell said:

You might also try the screwy way - meaning regex (what else ?)  :idiot:

#include <Date.au3>

$sDateTime = "25/12/2023 18:50:30"

$res = Execute("'" & StringRegExpReplace($sDateTime, "(\d+)/(\d+)/(\d+) (\d+):(\d+).*", _ 
    "' & _DateToMonth('$2',1) & ' $1 $3 ' & ('$4'>12 ? StringFormat('%02i', '$4'-12) & ':$5PM' : '$4:$5AM') & '") & "'") 

Msgbox(0,"", $res)

 

Thank You @mikell

But i created and its working well:

#include <Date.au3>
#include "DTC_Test.au3"
Local $sIn_Date, $sOut_Date
$sIn_Date      = "25/12/2023 11:59:30"
$sOut_Date  = _Date_Time_Convert(_DateAdd('s', Random(2, 8, 1), _Date_Time_Convert($sIn_Date, "dd/MM/yyyy HH:mm:ss", "yyyy/MM/dd HH:mm:ss")), "yyyy/MM/dd HH:mm:ss", "MMM dd yyyy HH:mmTT")
MsgBox(0, "Date-Conversion", "Webdate = " & $sIn_Date & @CRLF & "Newdate = " & $sOut_Date & @CRLF)

 

Link to comment
Share on other sites

Sorry, while my snippet works I didn't test yours  :P

#include <Date.au3>
$sDateTime = "25/12/2023 14:59:30"
$res = Execute("'" & StringRegExpReplace($sDateTime, "(\d+)/(\d+)/(\d+) (\d+):(\d+).*", _ 
    "' & _DateToMonth('$2',1) & ' $1 $3 ' & ('$4'>12 ? StringFormat('%02i', '$4'-12) & ':$5PM' : '$4:$5AM') & '") & "'") 
Msgbox(0,"", $res)

 

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