Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

Your explanation is not consistent. You state that the user is to enter a range as in "find me all numbers between x and y that are divisible by both 3 and 4." Later you state that you "input value 120 10 times". That is inconsistent with the problem so either the problem is stated incorrectly or you are not inputting the expected data. Decide what is the correct problem then write it up in pseudo-code before you write the actual code.

If a range is expected, make sure you test that it is a valid range (x <= y).

rproffitt commented: Programmers consistently solve the other problems first. +14
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

PS: Most good code editors have a hotkey where you place the cursor over a bracket and the hotkey toggles to/from the matching bracket.

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

you could make your logic a lot less complicated by something like

if (score > 100)
    \\invalid
else if (score >= 90)
    \\A+
else if (score >= 80)
    \\A
else if (score >= 75)
    \\A-

etc.

You should also pick one of the more widely accepted methods of using brace brackets. For example

if (condition) {
    statement;
    statement;
}

or

if (condition)
{
    statement;
    statement;
}

but not

if (condition)
{   statement;
    statement;
}

If you'd done that your bracket mismatch problem would have been immediately obvious.

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

You will have to change the WHERE clause to something like

WHERE DATEPART(month,TanggalLahir) = 9
  AND DATEPART(day,TanggalLahir) BETWEEN 1 AND 15
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

By the way, you may have noticed, just under the buttons labeled Start New Discussion and Realtime Chat, there is a menu bar that looks like

All   New   Solved   Unanswered   More

If you go to the Programming section and click on More it expands to

News Stories
Product Reviews
Interviews
Tutorials
Code Snippets

You might want to browse Tutorials and Code Snippets.

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

Welcome. If this is what you were looking for then please mark this thread solved. If not then feel free to post follow-up questions here.

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

You can find code samples for that in my snippets post here

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

Let me get back to you with the a-b.jpeg variant. The above code won't handle that yet. Before I do that, how does the other file name work? According to your original spec, this allows for something like

john-doe.jpg

Basically, only one file per person. How many files of this type do you have?

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

when i dubleclick the sortfiles.vbs exactly nothing happens

That's because you didn't read the instructions. I told you to run it by

cscript sortfiles.vbs

Apparently I was unclear in that you do this from the command line. vbScript files are executed by either cscript.exe (console) or wscript.exe (window). The default is wscript.exe and when run with the default, each echo pops up a msgbox. If you run it the way that I suggested you force it to run under cscript.exe and each echo writes a line to the console window. You can force cscript.exe to be the default by running (from a console window as Administrator)

cscript //h:cscript //nologo //s

Following that you can run the script from the command line by simply typing

sortfiles

It will take longer to run with all the echo statements but it's worthwhile in case something goes wrong - you can see exactly where it stops.

Okay i got it, but it sems like i have titles with just a-b.jpeg is it possible to process like that also ?

It certainly is but you didn't include that in the original spec. You could change the code to

set fso = CreateObject("Scripting.FileSystemObject")

for each file in fso.GetFolder(".").Files

    ext = lcase(fso.GetExtensionName(file.Name))

    if ext = "jpg" or ext = "jpeg" Then
        flds = Split(file.Name,"-")
        if Ubound(flds) >= 2 Then
            folder = flds(0) & "-" & flds(1) & "\"
            if not fso.FolderExists(folder) Then
                Wscript.Echo "Creating folder",folder
                fso.CreateFolder(folder)
            end if
            Wscript.Echo "Moving:",file.Name
            Wscript.Echo "    To:",folder …
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

The script looks at all jpg files in the folder. If the file name has at least three fields separated by "-" then it creates a folder name from the first two fields and moves the file. In other words, it will process

a-b-c.jpg
a-b-c-d.jpg
a-b-c-d-e.jpg
etc

but not

a-b.jpg

If you replace

fso.MoveFile file.Name, folder

with

'fso.MoveFile file.Name, folder

(commented out) then you can run the script to see what files would be moved without actually moving them. When you say "nothing happens" what exactly do you mean? What is echoed back in the command window? Did you save the script file in the same folder as your jpg files? I tested the script by creating the files

Stefan-Rafa-400x500-123uirjht5-1.jpg
Stefan-Rafa-300x300-12a32s-1.jpg
Stefan-Rafa-100-123uirjht5-1.jpg
John-Doe-400x500-123uirjht5-1.jpg
John-Doe-3-1423555-400x200.jpg
John-Doe-300x300-123uirjht5-1.jpg

and running the script. It worked as I understand you wanted it to.

D:\test>dir /s
 Volume in drive D is D-Data
 Volume Serial Number is 366A-6FA3

 Directory of D:\test

2017-08-21  08:14    <DIR>          .
2017-08-21  08:14    <DIR>          ..
2017-08-21  08:14                 0 John-Doe-300x300-123uirjht5-1.jpg
2017-08-21  08:14                 0 John-Doe-3-1423555-400x200.jpg
2017-08-21  08:14                 0 John-Doe-400x500-123uirjht5-1.jpg
2017-08-21  08:14               613 sortfiles.vbs
2017-08-21  08:14                 0 Stefan-Rafa-100-123uirjht5-1.jpg
2017-08-21  08:14                 0 Stefan-Rafa-300x300-12a32s-1.jpg
2017-08-21  08:14                 0 Stefan-Rafa-400x500-123uirjht5-1.jpg
               7 File(s)            613 bytes

     Total Files Listed:
               7 File(s)            613 bytes
               2 Dir(s)  916,313,260,032 bytes free

D:\test>cscript sortfiles.vbs
Creating folder John-Doe\
Moving: John-Doe-3-1423555-400x200.jpg
    To: John-Doe\
Moving: John-Doe-300x300-123uirjht5-1.jpg
    To: John-Doe\
Moving: John-Doe-400x500-123uirjht5-1.jpg
    To: John-Doe\
Creating folder Stefan-Rafa\
Moving: Stefan-Rafa-100-123uirjht5-1.jpg
    To: Stefan-Rafa\
Moving: Stefan-Rafa-300x300-12a32s-1.jpg
    To: Stefan-Rafa\
Moving: Stefan-Rafa-400x500-123uirjht5-1.jpg
    To: Stefan-Rafa\

D:\test>dir /s
 Volume in drive D is D-Data
 Volume Serial Number …
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

I don't normaly just provide code but

  1. It's pretty simple
  2. I'm really bored

Copy the following code into a file named SortFiles.vbs in the same folder containing your images. If you run it by

cscript sortfiles.vbs

the script will create the required folders under the current folder and move the files into each folder as requested. I suggest that you make a copy of the images in another folder for safe-keeping before you run the script. You can always delete the copy after you see if the results are what you wanted.

set fso = CreateObject("Scripting.FileSystemObject")

for each file in fso.GetFolder(".").Files
    if lcase(fso.GetExtensionName(file.Name)) = "jpg" Then
        flds = Split(file.Name,"-")
        if Ubound(flds) >= 2 Then
            folder = flds(0) & "-" & flds(1) & "\"
            if not fso.FolderExists(folder) Then
                Wscript.Echo "Creating folder",folder
                fso.CreateFolder(folder)
            end if
            Wscript.Echo "Moving:",file.Name
            Wscript.Echo "    To:",folder
            fso.MoveFile file.Name, folder
        end if
    end if
next
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

For the record, Resilio Sync works between Long Island and Winnipeg and I did not have to consider firewalls. Traffic is encrypted. Synching that is interrrupted by a disconnect is automatically resumed on reconnect. It's worth checking out.

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

If all else fails there is always the free version of Resilio Sync formerly BitTorrent Sync. I use it to sync a folder on my laptop (Winnipeg) with one in Long Island.

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

The example code here should help. If you are still stuck then post your code here and we'll have a look.

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

i tried. it says runtime error

Then you have your answer. Wouldn't that have been easier than asking us to do your work for you?

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

Why don't you just try it and see for yourself?

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

@Subbu_2 - If you want to know when this issue is sorted out then I suggest you bookmark the thread and check on it periodically instead of putting the onus on the OP to contact you. Or, if you go to the first post in the thread and click on the push-pin (assuming you have email enabled) you will be notified when new posts are made in this thread.

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

How do you want this to work? Your brief description leaves several possibilities. No point in suggesting the ones you don't want. For example, you could have a textbox with a text changed event handler that automatically populates a listbox based on what you type as you type it. This may or may not work depending on the dataset you are getting the matches from. It could be a database and if it is large and you can't use the index, the results may take too long to filter.

You say "display the data after inputting the ID" which does not imply auto-search but you don't want a button which sort of does imply auto-search.

You might even get away with a drop down combo box.

More detail means a better answer.

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

Why do you insist on writing this in VBA? Why not vb.net which has more capabilities and less overhead?

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

Works for me here as well in Canada. Windows 10 & Chrome. Also works in Firefox. I might help if you told us what OS and browser, or even what device you are trying to view it on. It's kind of like saying "My car doesn't work. What is wrong with it?"

rproffitt commented: Location matters. Seems some parts of the galaxy block Vimeo. +0
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

Can you be a little more specific?

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

Back to my question. If you want to know how long it takes to do the add, doing it through vba is pointless. Just run the executable directly. Also, you are just going to get a value of 0 for testing one addition. Even if you put in a loop to do the operation a million times you won't be able to distinguish between the time it takes to do the addition and the time spent on the rest of the loop processing.

As for writing the text file, try putting the full path and file name of the file you want to write. It's entirely possible the file is being created, just not where you expect it to be.

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

Possibly. I can't see anything useful in what OP is trying to do, but there is nothing overtly malicious either. I'm basically just trying to show him how two simple things work. At this point I think I'll just give up.

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

As an afterthought, I still don't understand why you want to do this through vba. Who cares if it takes a while to build it theough the IDE? You only have to do that when the source code changes. You only have to automate something when it has to be done repeatedly. And if you are going to do it through vba, starting your vba app is going to be a manual process anyway (most likely) so what have you gained by adding in the extra step?

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

The command line you are executing with Shell has spaces in it so you have to add extra quotes just like you would if you were running it from the command line. For example, if you ran the following from the command line

C:> C:\Program Files\Folder\test.exe arg1

you would get an error so you would have to type it as

C:> "C:\Program Files\Folder\test.exe" arg1

Inside vba you would have to do

ret = Shell("""C:\Program Files\Folder\test.exe"" arg1", vbHide)
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

Can you build the exe file from the command line?

Can you build the exe file using the same command but from within vba via the Shell command?

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

i used batch file in order to lauch Vs compiler

I still don't understand why you are doing that.

i dont know if it is possible directly through VBA or not

I don't have Microsoft Office so I can't test this so I suppose the best way to find out is to follow my steps above. Make a small test VBA that does nothing but run an exe.

but i didn't store the time process in the text file, how can you explain this

I can't. Mostly because your console application (which somehow has a form) is a black box and you didn't post the code. If you are going to give me the information I need to help in bits and pieces then one of two things is going to happen

  1. You might get an answer but it wiull take a very long time.
  2. I'll get tired of asking for more information and I'll just quit helping.
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

I'm not clear on what you are asking but my usual approach when trying to automate something is to do it in stages rather than jumping immediately to the final step. What you are trying to do (from what I gather) is

vba -> batch file -> devenv -> build solution

The first thing I'd do is try running the build directly from the command line

"C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\devenv.exe" "d:\my\Documents\Visual Studio Projects\ClipToJPG\ClipToJPG.sln" /build

then check to make sure the solution executable has been created. Once you know that works you can try shelling the same command line from within VBA (delete the solution executable first so you can see if it has been recreated).

Then you can create a simple batch file to do something like launch an app (like calc). Make sure this runs from the command line, then try to execute it from VBA. This will show that you can execute a batch file.

Once that works, try creating a batch file to execute the same vb.net build (although I don't see why you need to add this complication). Try running that from within VBA.

The trick (if you can call it that although it's just basic troubleshooting) is to see where the problem is. If you just throw all the parts together and it doesn't work then it's hard to figure out which part is the problem.

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

Try Shelling devenv instead of test.bat

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

Read the message. It says you have a syntax error. I tried

devenv clipjpg.sln /build

on one of my projects and it compiled/built the executable with no problems.

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

You can run devenv.exe and build your project from the command line. Type

devenv /?

to get the command line arguments/switches. You'll have to spawn it as an external process. Use the vba Shell call to do that

ret = Shell("command line with args", vbNormalFocus)
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

You have a couple of problems.

You have to write your own factorial function. However, pow, and cos are in math.h so unless one of your compiler switches is doing something weird they should be defined. I don't use gcc so I can't help there.

Your series expansion is incorrect. Your powers have to be 2, 4, 6... instead of 1, 2, 3...

Your parameters for pow are reversed. Try

double my_cos(double c) {

    int sign = -1;
    double result = 1.0;

    for (int i=2; i<=10; i+=2) {
        result += sign * pow(c,i) / factorial(i);
        sign   = -sign;
    }

    return result;
}

If you need i to be the loop counter you could do

double my_cos(double c) {

    int sign = -1;
    double result = 1.0;

    for (int i=1; i<=10; i++) {
        result += sign * pow(c,2*i) / factorial(2*i);
        sign   = -sign;
    }

    return result;
}
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

RE: PM. Your input routine should look like

void getUserInput(int *numHospitalRooms, int *numFlowers)
{
    do {
        printf("\nHow many hospital rooms: ");
        scanf("%d", numHospitalRooms);
        if (*numHospitalRooms < 1 || *numHospitalRooms > 5)
        {
            printf("\nInvalid number of rooms, room number must be between 1-5!\n");
        }

    }while((*numHospitalRooms < 1 || *numHospitalRooms > 5));

    do {
        printf("\nEnter number of flowers: ");
        scanf("%d", numFlowers);

        if (*numFlowers < 0)
        {
            printf("\nInvalid number of flowers, negative values are not accepted!\n");
        }

    }while((*numFlowers < 0));
}

Compare the placement of the * and & operators with your original code. You'll also have to make sure that you account for the fact that numHospitalRooms ranges from 1-5 but the array index must be from 0-4. Your calc would then be

float totalCost = (flowerCost + hospitalRoomsPrices_Array[numHospitalRooms] - 1);
catastrophe2 commented: OMG you are a life saver!!! thanks a lot! i suspected & in scanf but i only used it because thats how syntax should be as i learned for c +0
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

Your declaration is

void getUserInput(int *numHospitalRooms, int *numFlowers);

but you are calling it with

getUserInput(numHospitalRooms, numFlowers);

You define the parameters as pointer to int but you are passing int. You'' have to change your call to

getUserInput(&numHospitalRooms, &numFlowers);

Likewise, within getUserInput, you will have to change all variable references to reflect the fact that the parameters are pointers. Thus instead of

if (numHospitalRooms < 1 || numHospitalRooms > 5)

you'll have to use

if (*numHospitalRooms < 1 || *numHospitalRooms > 5)
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

Glad to help. Come on back if you have more questions.

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

I strongly urge you to get into the habit of naming your controls for their purpose. For demo purposes, Button1 and Checkbox1 are fine but in a larger program with many controls it will become impossible to follow your code. A control named btnSubmitForm is a lot clearer than Button17.

rproffitt commented: The old "what does this do?" problem. +12
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

You don't need the line

Dim settings As New My.MySettings

Delete it. Go to

Project -> Properties

then select the Settings tab. Create a variable named ButtonVisible. You should use a name like that rather than checked because it more clearly indicates what state you are trying to preserve. Make ButtonVisible a Boolean. Set the Value field to False.

Your code will look like

Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        Button1.Visible = My.Settings.ButtonVisible
        CheckBox1.Checked = My.Settings.ButtonVisible

    End Sub

    Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing

        My.Settings.ButtonVisible = Button1.Visible

    End Sub

    Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged

        Dim chk As CheckBox = sender
        Button1.Visible = chk.Checked

    End Sub

End Class
rproffitt commented: Classy. +0
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

Assuming that your settings variable is a Boolean you can just do

CheckBox1.Checked = My.Settings.check
Button1.Visible = My.Settings.check

in your form load event handler. You'll want to restore the Checkbox state as well so the two stay in sync. Just make that in the form closing handler you do

My.Settings.check = Button1.Visible

to save the last state.

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

How about modifying the bot until you find the problem so that it stops invalidating the links? Better to let a few dead links through for now instead of killing everything.

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

problem is: both text box show same data

Of course they do. Your code

Me.txtamount.Text = .SubItems(mlngCUST_LAST_IDX)
Me.txtdate.Text   = .SubItems(mlngCUST_LAST_IDX)

is assigning the same value to both textboxes. C hange it to

Me.txtamount.Text = .SubItems(mlngCUST_LAST_IDX)
Me.txtdate.Text   = .SubItems(mlngCUST_DATE_IDX)
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

It is possible that your connection somehow got switched to "metered". If set to metered, downloads are deferred, although for how long I am not sure. I've attached a script (vbs) that you can execute to get a connection's metered/non-metered status and set it to one state or the other.

At home I have a 160 gig/month connection but at the cottage I have a cap of 3 gig/month so I set the cottage connection to metered to defer the download of updates.

'
'   Name:
'
'       metered.vbs
'
'   Description:
'
'       Command line utility to set an internet connection to metered
'       or non-metered
'
'   Usage:
'
'       metered
'
'           Show existing profiles
'
'       metered <profile>
'
'           Show metered/non-metered status of <profile>
'
'       metered <profile> ON | OFF
'
'           Set metered status of <profile> to on or off
'
'   Notes:
'
'       The default engine for running scripts is wscript.exe. Before
'       running this script you should set the default engine to cscript.exe
'       (command line - wscript is windowed). Open a command shell as
'       Administrator and enter:
'
'           cscript //nologo //h:cscript //s
'
'       You will only have to do this once.
'
'   Audit:
'
'       2017-02-28  rj  tweaked output format slightly
'       2016-11-10  rj  original code
'

set wso = CreateObject("Wscript.Shell")
set arg = Wscript.Arguments

Select Case arg.Count

    Case 0  'no args - show all profile names

        profiles = Filter(ExecCmd("netsh wlan show profiles"),":")
        Wscript.Echo Join(profiles,vbcrlf) …
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

Yes. It's the description of the structure and API (application programming interface) of a document. For details please see the w3 description.

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

A Ceasar cyper encodes by shifting letters in one direction, and decodes by shifting in the opposite direction. key is the number of places to shift. If the user wants to decode then key is negated to shift in the opposite direction.

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

Further...

The if statement expects an expression that evaluates to true or false. The statement

if (app.activeDocument.pathItems[0].filled == true)

could be better written as

if (app.activeDocument.pathItems[0].filled)
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

That's odd because I posted it and it seemed fine. Then I refreshed the page and it was still fine. Perhaps there is some post-post-processing going on. Is there some automatic process crawling the threads and checking to see if the links are actually valid? If so then maybe that's the thing that is broken.

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

OK. It displays correctly and the link works. Maybe that's the secret - use [] and () to embed the link.

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

Let's see what happens if you embed the link like this.

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

Either

if (int(dmin) - 30)

or

dmin = int(dsec / 60)
if (dmin = 30)

as for 0.50, I don't know what that represents. What are the units? Is that half a minute, half an hour or half a day?

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

By the way, if you are just working with time strings you get

>>> datetime.datetime.strptime("01:23 PM","%H:%M %p")
datetime.datetime(1900, 1, 1, 1, 23)

It defaults the date to 1900-01-01 which shouldn't be a problem if you are just interested in differences. You also might want to do an abs in case t2 < t1.

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

You can convert a datetime string to a datetime value as long as you properly match the format of the string. For example

import datetime

t1 = "02/11/2017 10:43 AM"
t2 = "02/27/2017 01:11 PM"

d1 = datetime.datetime.strptime(t1, "%m/%d/%Y %H:%M %p")
d2 = datetime.datetime.strptime(t2, "%m/%d/%Y %H:%M %p")

dsec = (d2 - d1).total_seconds()
dmin = dsec / 60

print(t1,t2)
print(d1,d2)
print(dsec)
print(dmin)

results in

02/11/2017 10:43 AM 02/27/2017 01:11 PM
2017-02-11 10:43:00 2017-02-27 01:11:00
1348080.0
22468.0