gcue Posted January 18, 2024 Posted January 18, 2024 hi world! trying to get values for current min date current min time current max date current max time $string = '"min": "2023-11-20T015:32:20",' & @LF & _ '"max": "2023-12-17T20:01:05"' $new_min_date = "2024-01-01" $new_min_time = "00:00:00" $new_max_date = "2024-01-17" $new_max_time = "23:59:59" $current_min_date = StringRegExp($string, '^[\"[min]+\"\:\h\"][\d]+T', 3) $current_max_date = StringRegExp($string, '^[\"[max]+\"\:\h\"][\d]+T', 3) $current_min_time = StringRegExp($string, '^[\"[min]+\"\:\h\"[\d]+T]', 3) $current_max_time = StringRegExp($string, '^[\"[max]+\"\:\h\"[\d]+T]', 3) then based on different conditions (which i didnt add to avoid noise), i would like to replace current min date/time with new min date/time thank you in advance!!
Developers Solution Jos Posted January 18, 2024 Developers Solution Posted January 18, 2024 Something like this maybe: $string = '"min": "2023-11-20T15:32:20",' & @LF & _ '"max": "2023-12-17T20:01:05"' $new_min_date = "2024-01-01" $new_min_time = "00:00:00" $new_max_date = "2024-01-17" $new_max_time = "23:59:59" $current_min_date = StringRegExp($string, '\"min+\":\s*\"([\d-]+)T[\d:]+', 3) If Not @error Then ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $current_min_date = ' & $current_min_date[0] & ' >Error code: ' & @error & @CRLF) ;### Debug Console $current_max_date = StringRegExp($string, '\"max+\":\s*\"([\d-]+)T[\d:]+', 3) If Not @error Then ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $current_max_date = ' & $current_max_date[0] & ' >Error code: ' & @error & @CRLF) ;### Debug Console $current_min_time = StringRegExp($string, '\"min+\":\s*\"[\d-]+T([\d:]+)', 3) If Not @error Then ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $current_min_time = ' & $current_min_time[0] & ' >Error code: ' & @error & @CRLF) ;### Debug Console $current_max_time = StringRegExp($string, '\"max+\":\s*\"[\d-]+T([\d:]+)', 3) If Not @error Then ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $current_max_time = ' & $current_max_time[0] & ' >Error code: ' & @error & @CRLF) ;### Debug Console ; Insert new Dates & Times $string = StringRegExpReplace($string, '(\"min+\":\s*\")[\d-]+(T[\d:]+)', "${1}" & $new_min_date & "${2}") $string = StringRegExpReplace($string, '(.*\"min+\":\s*\"[\d-]+)T[\d:]+', "${1}" & $new_min_time & "${2}") $string = StringRegExpReplace($string, '(.*\"max+\":\s*\")[\d-]+(T[\d:]+)', "${1}" & $new_min_date & "${2}") $string = StringRegExpReplace($string, '(.*\"max+\":\s*\"[\d-]+)T[\d:]+', "${1}" & $new_min_time & "${2}") ConsoleWrite('New $string = ' & @CRLF & $string & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console 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.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now