How to resolve the algorithm Date manipulation step by step in the Run BASIC programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Date manipulation step by step in the Run BASIC programming language

Table of Contents

Problem Statement

Given the date string "March 7 2009 7:30pm EST", output the time 12 hours later in any human-readable format. As extra credit, display the resulting time in a time zone different from your own.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Date manipulation step by step in the Run BASIC programming language

Source code in the run programming language

theDate$ = "March 7 2009 7:30pm EST"

monthName$ = "January February March April May June July August September October November December"
for i = 1 to 12
  if word$(theDate$,1) = word$(monthName$,i) then monthNum = i			' turn month name to number
next i
d 	= val(date$(monthNum;"/";word$(theDate$,2);"/";word$(theDate$,3)))	' days since Jan 1 1901
t$	= word$(theDate$,4)				' get time from theDate$
t1$	= word$(t$,1,"pm")				' strip pm
t2$	= word$(t1$,1,":") + "." + word$(t1$,2,":")	' replace : with .
t	= val(t2$)
if right$(t$,2) = "pm" then t = t + 12
ap$	= "pm"
if t + 12 > 24 then 
  d	= d + 1			' if over 24 hours add 1 to days since 1/1/1901
  ap$	= "am"
end if
print date$(d);" ";t1$;ap$

  

You may also check:How to resolve the algorithm Display a linear combination step by step in the C# programming language
You may also check:How to resolve the algorithm Integer comparison step by step in the bc programming language
You may also check:How to resolve the algorithm Integer sequence step by step in the Ring programming language
You may also check:How to resolve the algorithm Create a two-dimensional array at runtime step by step in the AutoHotkey programming language
You may also check:How to resolve the algorithm Merge and aggregate datasets step by step in the Phix programming language