Traveling from Melk to Hallstatt will take an entire day with multiple connections. If you rent a car, it will take a half day.
Both assertions are false.
By car you would need about 2:30 hours, by train 3:15 hours.
The most comfortable train connection, having one change only, would be the CJX 5 (8:40am) from Melk to St. Pölten, changing to the D 1018 (9:13am) which arrives in Hallstatt at noon. Sunset is at 8:20pm. If you leave Hallstatt by the train REX 70 (6:32pm), change in Bad Ischl to Bus 150 (6:52pm), then you will arrive in Salzburg at 8:14pm, still at daylight. The bus to Salzburg is not only faster than the train, but is much more scenic. This proposed schedule will give you 6 hours in Hallstatt, IMHO more than enough for this little town.