More to the point, what's the relevance of %(aa,w) to the original post? They haven't indicated they have any am/pm flag. Never mind the fact the w option is for output, doubt it would make much difference when trying to read a time
The OP needs to have a read of the manual and figure out which tags suit their input (which may or may not require %aa)... paying particular attention to the %h and %H tags...