Chris Roberts
Chris Roberts

Reputation: 29

Check if DateTimeField contains a specific number

Let's say I have a number "5". How can I check if a DateTimeField value contains that number?

"25/10/15" should be true, while "20/10/12" should be false.

Upvotes: 0

Views: 39

Answers (1)

omri_saadon
omri_saadon

Reputation: 10621

Simple one line code.

from datetime import datetime

print ('5' in (str(datetime.now().strftime("%d/%m/%y"))))

Upvotes: 2

Related Questions