Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python Using Databases in Python Our Diary App Doing Data Entry

Anthony Grodowski
Anthony Grodowski
4,902 Points

Difference beetween ```.now()``` and ```.now```

I think I don't have a correct understanding on the difference between datetime.datetime.now and datetime.datetime.now(). Can someone clear that up for me?

1 Answer

Steven Parker
Steven Parker
231,248 Points

When you call a method, you put parentheses after the method name. WIthout them, you are referencing the method without invoking it.

So the first example would return the resut of calling the method (which would be the current date and time), but the second one is a reference to the method itself.

Anthony Grodowski
Anthony Grodowski
4,902 Points

Thanks Steven! So what's the point of putting that in here:

class Entry(Model):
    # content
    content = TextField() # it allows us to put as much text as we want
    # timestamp
    timestamp = DateTimeField(default = datetime.datetime.now)

if it's just referencing to the method and it doesn't return anything?

Steven Parker
Steven Parker
231,248 Points

It returns a reference to the method, which is assigned as the "default". So when a record is added without an explicit timestamp value, then the method will be called to fill the timestamp with the current date/time.